android RadioButton单选按钮效果
activity_main.xml
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<RadioButton
android:id="@+id/xiaoxi"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="消息"
android:button="@null"
android:textSize="20sp"
android:gravity="center"
android:checked="true"
android:drawableTop="@drawable/selector_bar_1"/>
<RadioButton
android:id="@+id/lianxiren"
android:layout_weight="1"
android:button="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="联系人"
android:gravity="center"
android:drawableTop="@drawable/selector_bar_2"
android:textSize="20sp"/>
<RadioButton
android:id="@+id/dongtai"
android:layout_weight="1"
android:button="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:drawableTop="@drawable/selector_bar_3"
android:text="动态"/>
</RadioGroup>
---------------------------在drawable下新建文件----------------------
1.selector_bar_1.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/bar_1_select" android:state_checked="true"/>
<item android:drawable="@mipmap/bar_1_unselect" android:state_checked="false"/>
</selector>
2.selector_bar_1.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/bar_2_selector" android:state_checked="true"/>
<item android:drawable="@mipmap/bar_2_unselector" android:state_checked="false"/>
</selector>
3.selector_bar_1.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/bar_3_select" android:state_checked="true"/>
<item android:drawable="@mipmap/bar_3_unselect" android:state_checked="false"/>
</selector>
素材:
效果: