日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android开发之RadioButton选择改变字体颜色与背景色

發布時間:2023/12/15 Android 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android开发之RadioButton选择改变字体颜色与背景色 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

先看效果圖:

方法一:

公司理財項目里面用到的,當選中radioButton后要改變背景色和自提顏色,試了好幾次這么都不行。

于是想到了selecter背景選擇器,可是怎么寫都不對。終于找到一種成功的寫法了。下面是字體顏色改變的方法

shape_financing_text_color.xml

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:color="#ffffff" android:state_checked="true" /><item android:color="#000000" android:state_checked="false" /> </selector>

下面是整個radiobutton背景顏色改變的方法

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_checked="true"><shape><solid android:color="@color/colorMain" /><stroke android:width="@dimen/dp_1" android:color="@color/colorKeyBoard" /></shape></item><item android:state_checked="false"><shape><stroke android:width="@dimen/dp_1" android:color="@color/colorKeyBoard" /></shape></item> </selector>

如何引用呢?

很簡單如下:

在textcolor中引用這個選擇器就好了

<RadioGroupandroid:id="@+id/rg_financing_home"android:layout_width="match_parent"android:layout_height="@dimen/dp_45"android:orientation="horizontal"><RadioButtonandroid:id="@+id/rb_financing_home"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:background="@drawable/shape_financing_bg"android:button="@null"android:checked="true"android:gravity="center"android:text="首頁"android:textColor="@drawable/shape_financing_text_color" /><RadioButtonandroid:id="@+id/rb_financing_money"android:layout_width="0dp"android:layout_height="match_parent"android:layout_marginLeft="0.5dp"android:layout_marginRight="0.5dp"android:layout_weight="1"android:background="@drawable/shape_financing_bg"android:button="@null"android:gravity="center"android:text="資產"android:textColor="@drawable/shape_financing_text_color" /><RadioButtonandroid:id="@+id/rb_financing_mine"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:background="@drawable/shape_financing_bg"android:button="@null"android:gravity="center"android:text="我的"android:textColor="@drawable/shape_financing_text_color" /></RadioGroup>

?

?

方法二:

看小效果圖:

先創建selecter

放在res/color里面

沒有color文件夾需要自己創建color文件夾哈

text_color.xml

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:color="#66ff66" android:state_checked="true" /><item android:color="#00ffff" android:state_checked="false" /> </selector>

?

?

然后在xml中引用即可

android:textColor="@color/text_color"

<RadioGroupandroid:id="@+id/rg_financing_home"android:layout_width="match_parent"android:layout_height="@dimen/dp_45"android:orientation="horizontal"><RadioButtonandroid:id="@+id/rb_financing_home"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:background="@drawable/shape_financing_bg"android:button="@null"android:checked="true"android:gravity="center"android:text="首頁"android:textColor="@color/text_color" /><RadioButtonandroid:id="@+id/rb_financing_money"android:layout_width="0dp"android:layout_height="match_parent"android:layout_marginLeft="0.5dp"android:layout_marginRight="0.5dp"android:layout_weight="1"android:background="@drawable/shape_financing_bg"android:button="@null"android:gravity="center"android:text="資產"android:textColor="@color/text_color" /><RadioButtonandroid:id="@+id/rb_financing_mine"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:background="@drawable/shape_financing_bg"android:button="@null"android:gravity="center"android:text="我的"android:textColor="@color/text_color" /></RadioGroup>

?

總結

以上是生活随笔為你收集整理的Android开发之RadioButton选择改变字体颜色与背景色的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。