BottomTabBar 配合标题栏切换fragment简单使用

依赖:

compile 'com.hjm:BottomTabBar:1.1.1'


xml-1:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fresco="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#03A9F4"
        android:padding="10dp">

        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/da"
            app:roundAsCircle="true"
            fresco:roundAsCircle="true"
            android:layout_width="@dimen/x50"
            android:layout_height="@dimen/x50"
            android:layout_centerVertical="true"
            android:layout_gravity="center_vertical" />

        <TextView
            android:id="@+id/title_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="标题"
            android:textColor="#fff"
            android:textSize="23sp"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/edit"
            android:layout_width="@dimen/x33"
            android:layout_height="@dimen/x33"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/right" />
    </RelativeLayout>


</LinearLayout>

xml-2:


<include
    android:id="@+id/title"
    layout="@layout/title">
</include>

<com.hjm.bottomtabbar.BottomTabBar
    android:id="@+id/btb"
    android:layout_width="match_parent"
    android:layout_height="match_parent"></com.hjm.bottomtabbar.BottomTabBar>


MainActity:

//获取按钮控件
mb = (BottomTabBar) findViewById(R.id.btb);
mb.init(getSupportFragmentManager())
        .setImgSize(50, 50)
        .setFontSize(20)
        .setTabPadding(4, 6, 10)
        .setChangeColor(Color.BLUE, Color.DKGRAY)
        .addTabItem("推荐", R.drawable.raw_1500085367, Fragment1.class)
        .addTabItem("段子",R.drawable.raw_1500085899, Fragment2.class)
        .addTabItem("视频", R.drawable.raw_1500086067, Fragment3.class)
        .setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
            @Override
            public void onTabChange(int position, String name) {
                if (name.equals("推荐")) {
                    title_tv.setText("推荐");
                }
                if (name.equals("段子")) {
                    title_tv.setText("段子");
                }
                if (name.equals("视频")) {
                    title_tv.setText("视频");
                }
            }
        });





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值