欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2022-03-12 07:52:49
效果图activity_main.xml

效果图

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

 

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