使用BottomTabBar实现底部切换:
1、导入依赖
compile 'com.hjm:BottomTabBar:1.1.1'
2、在XML中定义控件
<com.hjm.bottomtabbar.BottomTabBar
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.hjm.bottomtabbar.BottomTabBar>
3.MainActivity中的设置
public class MainActivity extends AppCompatActivity {
private TopBar mTb;
private BottomTabBar bottomTabBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTb = findViewById(R.id.topbar);
mTb.setLeftButtonVisibilty(false);
mTb.setRightButtonVisibilty(false);
bottomTabBar = findViewById(R.id.bottomtb);
bottomTabBar.init(getSupportFragmentManager())
.setImgSize(50,50)
.setFontSize(8)
.setTabPadding(4,6,10)
.setChangeColor(Color.RED,Color.DKGRAY)
.addTabItem("首页",R.drawable.a,FragmentOne.class)
.addTabItem("分类",R.drawable.a,FragmentTwo.class)
.addTabItem("购物车",R.drawable.a,FragmentThree.class)
.addTabItem("我的",R.drawable.a,FragmentFour.class)
.isShowDivider(false)
.setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
@Override
public void onTabChange(int position, String name) {
//mTb.setCenconTextViewVisibility(true,name);
}
});
}
}