当前位置: 移动技术网 > 移动技术>移动开发>Android > Android RadioGroup RadioButton 自定义样式------按钮式

Android RadioGroup RadioButton 自定义样式------按钮式

2020年09月01日  | 移动技术网移动技术  | 我要评论
效果图activity_main.xml<RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton a.

效果图

 

activity_main.xml

<RadioGroup
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <RadioButton
                    android:id="@+id/rb_one"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    style="@style/cus_radio"
                    android:drawablePadding="0dp"
                    android:drawableLeft="@android:drawable/star_on"
                    android:checked="true"
                    android:text="@string/str_one"/>

                <RadioButton
                    android:id="@+id/rb_two"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    style="@style/cus_radio"
                    android:drawableLeft="@android:drawable/star_on"
                    android:text="@string/str_two"/>

                <RadioButton
                    android:id="@+id/rb_three"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    style="@style/cus_radio"
                    android:drawableLeft="@android:drawable/star_on"
                    android:text="@string/str_three"/>
            </RadioGroup>

style.xml

<style name="cus_radio">
        <item name="android:button">@null</item>
        <item name="android:gravity">center</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:padding">@dimen/font_tiny</item>
        <item name="android:background">@drawable/radio</item>
        <item name="android:layout_weight">1</item>
        <item name="android:layout_margin">5dp</item>
    </style>

drawable/radio.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false"
        android:drawable="@drawable/btn_orange_normal_shape" />
    <item android:state_checked="true"
        android:drawable="@drawable/btn_orange_pressed_shape" />
</selector>

 

本文地址:https://blog.csdn.net/zhu_nana/article/details/108572754

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网