Android: UI--顶部导航栏(颜色渐变)+Fragmen

2019-06-26  本文已影响0人  tylorsenna

底部导航栏使用

implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.46'
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉状态栏
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
        setContentView(R.layout.activity_follow);
        mBottomNavigationBar = findViewById(R.id.bottom_navigation_bar);
        InitNavigationBar();
    }

    private void InitNavigationBar() {
        mBottomNavigationBar.setTabSelectedListener(this);
        mBottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED);
        mBottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_DEFAULT);        mBottomNavigationBar.setTextDirection(BottomNavigationBar.TEXT_DIRECTION_INHERIT);
        mBottomNavigationBar
                .addItem(new BottomNavigationItem(R.mipmap.bottom_tuijian_active_72, "推荐").setInactiveIconResource(R.mipmap.bottom_tuijian_72).setActiveColor(R.color.black))
                .addItem(new BottomNavigationItem(R.mipmap.bottom_yule_active_72, "娱乐").setInactiveIconResource(R.mipmap.bottom_yule_72).setActiveColor(R.color.black))
                .addItem(new BottomNavigationItem(R.mipmap.bottom_guanzhu_active_72, "关注").setInactiveIconResource(R.mipmap.bottom_guanzhu_72).setActiveColor(R.color.black))
                .addItem(new BottomNavigationItem(R.mipmap.bottom_yuba_active_72, "鱼吧").setInactiveIconResource(R.mipmap.bottom_yuba_72).setActiveColor(R.color.black))
                .addItem(new BottomNavigationItem(R.mipmap.bottom_faxian_active_72, "发现").setInactiveIconResource(R.mipmap.bottom_faxian_72).setActiveColor(R.color.black))
                .setFirstSelectedPosition(0)
                .initialise();

        fm = getSupportFragmentManager();
        transaction = fm.beginTransaction();

        if (mRecommendFragment == null) {
            mRecommendFragment = RecommendFragment.newInstance();
        }
        fragmentList = new ArrayList<>();
        fragmentList.add(mRecommendFragment);
        fragmentList.add(EntertainmentFragment.newInstance());
        fragmentList.add(FollowFragment.newInstance());
        fragmentList.add(FishbarFragment.newInstance());
        fragmentList.add(DiscoverFragment.newInstance());

        transaction.replace(R.id.frameLayout,mRecommendFragment);
        transaction.commit();
    }

顶部:

TabLayout + ViewPager + Fragment
<android.support.v4.view.ViewPager
        android:id="@+id/follow_viewPager"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <FrameLayout
            android:id="@+id/follow_live_frameLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </FrameLayout>
    </android.support.v4.view.ViewPager>
去除AppBarLayout下面的阴影
AppBarLayout有阴影.png
上一篇下一篇

猜你喜欢

热点阅读