仿微信 RadioButton 自定义点击效果

来源:互联网 发布:vb sub function区别 编辑:程序博客网 时间:2024/05/21 18:43

1.Android Studio

步骤:

1.选中drawable目录后点击鼠标右键New-Drawable resource file,如图:
这里写图片描述

2.输入文件名称,点击ok,如图:
这里写图片描述
3.新建好之后即为selector,如图:
这里写图片描述

4.自定义xml

    <item android:drawable="@drawable/tab_address_normal"  android:state_checked="true"/>    <!-- 选中时效果 -->    <item android:drawable="@drawable/tab_address_pressed" android:state_checked="false"/>    <!-- 未选中时效果 -->

5.在布局中使用自定义属性

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    >    <LinearLayout        android:orientation="vertical"        android:id="@+id/fragment"        android:layout_width="match_parent"        android:layout_height="wrap_content">    </LinearLayout>   <LinearLayout       android:background="@drawable/bottom_bar"       android:layout_alignParentBottom="true"       android:layout_width="match_parent"       android:layout_height="wrap_content">       <RadioGroup           android:id="@+id/radiogroup"           android:layout_width="match_parent"           android:layout_height="wrap_content"           android:gravity="center_horizontal"           android:orientation="horizontal">           <RadioButton               android:textColor="#eee"               android:id="@+id/first"               android:layout_width="0dp"               android:layout_height="wrap_content"               android:layout_weight="1"               android:button="@null"               android:drawableTop="@drawable/radio_image_talk"               android:gravity="center_horizontal"               android:text="聊天" />           <RadioButton               android:textColor="#eee"               android:id="@+id/two"               android:layout_width="0dp"               android:layout_height="wrap_content"               android:layout_weight="1"               android:button="@null"               android:drawableTop="@drawable/radio_image_address"               android:gravity="center_horizontal"               android:text="联系人" />           <RadioButton               android:textColor="#eee"               android:id="@+id/three"               android:layout_width="0dp"               android:layout_height="wrap_content"               android:layout_weight="1"               android:button="@null"               android:drawableTop="@drawable/radio_image_find"               android:gravity="center_horizontal"               android:text="朋友圈" />           <RadioButton               android:textColor="#eee"               android:id="@+id/four"               android:layout_width="0dp"               android:layout_height="wrap_content"               android:layout_weight="1"               android:button="@null"               android:drawableTop="@drawable/radio_image_setting"               android:gravity="center_horizontal"               android:text="设置" />       </RadioGroup>   </LinearLayout></RelativeLayout>

5.效果图
这里写图片描述
这里写图片描述

0 0
原创粉丝点击