1. 导依赖
compile 'com.hjm:BottomTabBar:1.1.1'
2. 在所实现的XML中定义一下该控件
3. 定义每个Fragment,这里列举一个
public class OneFragment extends Fragment{ @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment1, container, false); return view; } }
4. MainActivity中
//Fragment页面设置页 public class MainActivity extends AppCompatActivity { private BottomTabBar bottomTabBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bottomTabBar = findViewById(R.id.bottom_tab_bar); //初始化Fragment bottomTabBar.init(getSupportFragmentManager()) .setImgSize(50, 50) //图片大小 .setFontSize(12) //字体大小 .setTabPadding(4, 6, 10)//选项卡的间距 .setChangeColor(Color.RED, Color.BLUE) //选项卡的选择颜色 .addTabItem("首页", R.drawable.home_, ShouYe_Fragment.class) .addTabItem("分类", R.drawable.classify, FenLei_Fragment.class) .addTabItem("发现", R.drawable.cart, Cart_Fragment.class) .addTabItem("我的", R.drawable.mine, Mine_Fragment.class) .isShowDivider(true) //是否包含分割线 .setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() { @Override public void onTabChange(int position, String name) { Log.i("TGA", "位置:" + position + " 选项卡:" + name); } }); } }
效果图:
下面通过实例代码介绍下 Android_BottomTabBar
一:依赖
compile 'com.hjm:BottomTabBar:1.1.1'
二:布局
三:代码
public class MainActivity extends AppCompatActivity { @BindView(R.id.bottomtabbar) BottomTabBar bottomtabbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); bottomtabbar.init(getSupportFragmentManager()) .setImgSize(25, 25) .setFontSize(8) .setTabPadding(4, 6, 10) .setChangeColor(Color.RED, Color.BLACK) .addTabItem("精选", R.drawable.choiceness, ChoicenessFragment.class) .addTabItem("专题", R.drawable.dissertation, DissertationFragment.class) .addTabItem("发现", R.drawable.discover, DiscoverFragment.class) .addTabItem("我的", R.drawable.my, MyFragment.class) .isShowDivider(false) .setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() { @Override public void onTabChange(int position, String name) { } }) .setTabBarBackgroundResource(R.drawable.bottom_bg) .setBackgroundResource(R.drawable.bg_blue); } }
总结
以上所述是小编给大家介绍的Android使用BottomTabBar实现底部导航页效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!