RadioGroup+RadioButton组合方式打造简单实用的底部导航栏
代码块:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/fl_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/rg_content"> </FrameLayout> <RadioGroup
android:paddingTop="@dimen/dp_10"
android:id="@+id/rg_content"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_60"
android:layout_alignParentBottom="true"
android:background="@color/white"
android:orientation="horizontal"> <RadioButton
android:textColor="@drawable/tv_color_selected"
android:textSize="@dimen/dp_12"
android:text="首页"
android:button="@null"
android:gravity="center_horizontal"
android:drawableTop="@drawable/ic_home_selected"
android:id="@+id/rb_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/> <RadioButton
android:gravity="center_horizontal"
android:textColor="@drawable/tv_color_selected"
android:textSize="@dimen/dp_12"
android:text="产品"
android:button="@null"
android:drawableTop="@drawable/ic_loan_selected"
android:id="@+id/rb_money"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/> <RadioButton
android:gravity="center_horizontal"
android:textColor="@drawable/tv_color_selected"
android:textSize="@dimen/dp_12"
android:text="个人"
android:button="@null"
android:drawableTop="@drawable/ic_me_selected"
android:id="@+id/rb_mine"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</RadioGroup> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="@+id/rg_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/dp_60"
android:background="@color/line_background"></View>
</RelativeLayout>
效果图片: