首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带矢量绘图的RadioButton

带矢量绘图的RadioButton
EN

Stack Overflow用户
提问于 2016-12-08 13:17:24
回答 1查看 1.1K关注 0票数 1

我试着用RadioButtons来改变性别。现在它看起来像

我使用矢量绘图作为图标。我想让它@color:colorAccent,并改变它的背景为一个白色的圆圈,当按钮被按下。怎么做才更好呢?

layout.xml

代码语言:javascript
复制
<RadioGroup
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="24dp">

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/radioButton"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:layout_weight="1"
                android:layout_marginEnd="8dp"
                android:button="@drawable/custom_btn_radio"/>

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/radioButton2"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:layout_weight="1"
                android:layout_marginStart="8dp"
                android:button="@drawable/custom_btn_radio"/>

        </LinearLayout>
    </RadioGroup>

custom_btn_radio.xml

代码语言:javascript
复制
<?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/human_male"/>
<item android:state_checked="true"
    android:drawable="@drawable/human_male"
    android:background="@android:color/white"
    android:tint="@color/colorAccent"/>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-08 13:37:50

您应该使用为不同的状态选择不同的绘图。

然后,对于颜色,在使用向量绘图时,您可以对它的属性进行动画化:AnimVector,这样您就可以对颜色进行动画化,即使它是一个零持续时间的动画(理论上,这不是我做过的事情)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41040461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档