<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:hjm="http://schemas.android.com/apk/res-auto"
>
<com.hjm.bottomtabbar.BottomTabBar
android:id="@+id/bottomtabbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
hjm:tab_divider_height="5dp"
hjm:tab_font_size="20sp"
>
</com.hjm.bottomtabbar.BottomTabBar>
</RelativeLayout>
代码实现
- public class SecondActivity extends AppCompatActivity {
- private BottomTabBar bottomTabBar;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_second);
- bottomTabBar = (BottomTabBar) findViewById(R.id.bottomtabbar);
- bottomTabBar.init(getSupportFragmentManager())
- .setImgSize(70,70)
- .setFontSize(20)
- .setTabPadding(4,6,10)
- .setChangeColor(Color.RED,Color.DKGRAY)
- .addTabItem("首页",R.drawable.home_, Shouye_Fragment.class)
- .addTabItem("分类",R.drawable.classify, Fenlei_Fragment.class)
- .addTabItem("发现",R.drawable.find, Faxian_Fragment.class)
- .addTabItem("购物车",R.drawable.cart, GouWuChe_Fragment.class)
- .addTabItem("我的",R.drawable.mine, WoDe_Fragment.class)
- .isShowDivider(true)
- .setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
- @Override
- public void onTabChange(int position, String name) {
- }
- });
- }
- }
- 写五个Fragment举例一个
-
- public class Faxian_Fragment extends Fragment{
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_faxian,container,false);
- return view;
- }