1. 導(dǎo)依賴
compile 'com.hjm:BottomTabBar:1.1.1'
2. 在所實(shí)現(xiàn)的XML中定義一下該控件
<com.hjm.bottomtabbar.BottomTabBar android:id="@+id/bottom_tab_bar" android:layout_width="match_parent" android:layout_height="match_parent" ></com.hjm.bottomtabbar.BottomTabBar>
3. 定義每個(gè)Fragment,這里列舉一個(gè)
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頁(yè)面設(shè)置頁(yè)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)//選項(xiàng)卡的間距 .setChangeColor(Color.RED, Color.BLUE) //選項(xiàng)卡的選擇顏色 .addTabItem("首頁(yè)", R.drawable.home_, ShouYe_Fragment.class) .addTabItem("分類", R.drawable.classify, FenLei_Fragment.class) .addTabItem("發(fā)現(xiàn)", 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 + " 選項(xiàng)卡:" + name); } }); }}效果圖:

下面通過(guò)實(shí)例代碼介紹下 Android_BottomTabBar
一:依賴
compile 'com.hjm:BottomTabBar:1.1.1'
二:布局
<com.hjm.bottomtabbar.BottomTabBar android:id="@+id/bottomTabBar" android:layout_width="match_parent" android:layout_height="match_parent"> </com.hjm.bottomtabbar.BottomTabBar>
三:代碼
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("發(fā)現(xiàn)", 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); } } 總結(jié)
以上所述是小編給大家介紹的Android使用BottomTabBar實(shí)現(xiàn)底部導(dǎo)航頁(yè)效果,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選