android控件view,android控件(view)的默认(系统)样式查看

问题概述

UED给开发ui设计稿,这个时候,如果需要给单选控件RadioButton换图标,你知道需要ui给你什么切图吗?

查看一个控件的默认(系统)样式设置的方法

以RadioButton控件来说明

1. 查看RadioButton的两个参数的构造方法,可以看到默认样式com.android.internal.R.attr.radioButtonStyle

public RadioButton(Context context, AttributeSet attrs) {

this(context, attrs, com.android.internal.R.attr.radioButtonStyle);

}

2. 直接点击radioButtonStyle链接不过去,只能找文件了,可以从com.android.internal.R.attr.radioButtonStyle看出,是value资源文件夹中的attrs.xml文件中

项目的sdk的res中

f888555a1096d831e5eed67893fe83b8.png

res中的vlues文件夹中的attrs.xml文件可看到定义的

//values文件夹下attrs.xml文件

f951275da362cd7e48679e34bd14fb71.png

3. 查看主题themes.xml中的radioButtonStyle属性

//values文件夹下themes.xml文件

@style/Widget.CompoundButton.RadioButton

点击@style/Widget.CompoundButton.RadioButton可以看到

//styles.xml文件

点击?attr/listChoiceIndicatorSingle可以看到

//values文件夹下attrs.xml文件

又回到attrs.xml,继续在themes.xml中搜索listChoiceIndicatorSingle,可以看到

//values文件夹下themes.xml文件

@drawable/btn_radio

终于找到源头了

//drawable文件夹下btn_radio.xml文件

android:drawable="@drawable/btn_radio_on" />

android:drawable="@drawable/btn_radio_off" />

android:drawable="@drawable/btn_radio_on_pressed" />

android:drawable="@drawable/btn_radio_off_pressed" />

android:drawable="@drawable/btn_radio_on_selected" />

android:drawable="@drawable/btn_radio_off_selected" />

上面定义的状态很精细,而一般只需要选中和未选中状态。如下定义一个btn_radio.xml文件

//在自己的drawable文件夹下定义btn_radio.xml文件

点击btn_radio_off可以看到对应的图片资源,如下图

8a7f860f269ee5470c3720983a87ea47.png

总结一下:RadioButton控件是由主题中的radioButtonStyle属性控制,而 radioButtonStyle中是设置了控件的button属性,button属性间接引用listChoiceIndicatorSingle属性。这样可以知道RadioButton的按钮图标控件直接由button属性控制,间接的与主题中的radioButtonStyle和listChoiceIndicatorSingle相关,下面举例几种使用方法

RadioButton中直接修改android:button属性

//直接引用上面的btn_radio

android:button="@drawable/btn_radio""

…… />

styles.xml中定义样式,themes.xml中引用使用或者RadioButton引用使用

//styles.xml中定义样式

//themes.xml中引用使用

@style/RadioButtonStyle

//RadioButton引用使用

…… />

修改themes.xml中listChoiceIndicatorSingle属性(不推荐这种方式,listChoiceIndicatorSingle还被其他控件的属性引用,可能会造成不需要的修改效果)

//修改themes.xml中listChoiceIndicatorSingle属性

@drawable/btn_radio

此文要是对你有帮助,如果方便麻烦点个赞,谢谢!!!

本文地址:https://blog.csdn.net/kingyc123456789/article/details/107590740

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值