bottombar——Fragment

首先是依赖   compile 'com.hjm:BottomTabBar:1.1.1'

   下面是activity。xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.news.Activity.HomeActivity">

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

最后是Main的代码

public class HomeActivity extends AppCompatActivity {

    @InjectView(R.id.bar)
    BottomTabBar bar;
    private static final String Home = "首页";
    private static final String Buy = "西瓜视频";
    private static final String Shop = "微头条";
    private static final String Mine = "我的";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        ButterKnife.inject(this);
        bar.init(getSupportFragmentManager())
                .setImgSize(50, 50)  //底部标题栏图片的大小
                .setFontSize(15)  //图片下边文字大小
                .setChangeColor(Color.RED, Color.BLACK) //设置文字的颜色,选中红色,不选中黑色
                .addTabItem(Home, R.mipmap.a2t, R.mipmap.a2s, Fragment_home.class)//加载Fragment参数,分别是图片下面的文字,选中时候的图片,未选中时候的图片,对应的Fragment类
                .addTabItem(Buy, R.mipmap.a31, R.mipmap.a30, Fragment_vedio.class)
                .addTabItem(Shop, R.mipmap.a2z, R.mipmap.a2y, Fragment_headlines.class)
                .addTabItem(Mine, R.mipmap.a2v, R.mipmap.a2u, Fragment_mine.class)
                .isShowDivider(false);
    }
}
原文地址:https://www.cnblogs.com/leshen/p/8124874.html