作用:fragment+button //最快制作页面底部的四个RadioButto
1.倒依赖
compile 'com.hjm:BottomTabBar:1.1.1'
2.在xml中添加此控件:
<com.hjm.bottomtabbar.BottomTabBar
android:id="@+id/bottom_tab_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tab_divider_background="#FF0000"
app:tab_divider_height="5dp"
app:tab_font_size="6sp"
app:tab_img_font_padding="0dp"
app:tab_img_height="30dp"
app:tab_img_width="30dp"
app:tab_isshow_divider="true"
app:tab_padding_bottom="5dp"
app:tab_padding_top="8dp"
app:tab_selected_color="#000000"
app:tab_unselected_color="@color/colorPrimary" />
3.在Activity的Oncreate()方法中添加代码
@SuppressLint("ResourceType") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new); ButterKnife.bind(this); bottomTabBar.init(getSupportFragmentManager()) //设置图片的尺寸 .setImgSize(35, 35) //设置字体的尺寸 .setFontSize(10) //设置选中和未选中后的颜色 .setChangeColor(Color.RED, Color.GRAY) //前面第一个是点击后的图片,第二个是点击前的图片 .addTabItem("咨询", R.mipmap.kuangjia6, R.mipmap.newwen1, ZhiXun_Fragment.class) .addTabItem("话题", R.mipmap.xinkuang03, R.mipmap.xinkuang3, HuaTi_Fragment.class) .addTabItem("圈子", R.mipmap.shuangren_red1, R.mipmap. shuangren4, QuanZi_Fragment.class) .addTabItem("我的", R.mipmap.danren_red05, R.mipmap.danren5, Mine_Fragment.class) .isShowDivider(false); }
4 .控件属性
tab_bar_background | BottomTabBar的整体背景颜色 |
tab_img_width | 图片宽度 |
tab_img_height | 图片高度 |
tab_font_size | 文字尺寸 |
tab_padding_top | 上边距 |
tab_img_font_padding | 图片文字间隔 |
tab_padding_bottom | 下边距 |
tab_isshow_divider | 是否显示分割线 |
tab_divider_height | 分割线高度 |
tab_divider_background | 分割线背景 |
tab_selected_color | 选中的颜色 |
tab_unselected_color | 未选中的颜色 |