依赖:
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("视频"); } } });