Android中给TextView的Background设置selector不生效的问题解决

TextView中设置selector不生效

给TextView的selector设置属性android:state_pressed

错误的的selector代码示例:

javascript 复制代码
// selector不生效代码示例
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/yt_bg_normal_btn_tire" android:state_selected="false"/>
    <item android:drawable="@drawable/yt_bg_press_btn_tire" android:state_selected="true"/>
</selector>

正确的selector代码示例:

javascript 复制代码
// selector有效代码示例
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/yt_bg_normal_btn_tire" android:state_pressed="false"/>
    <item android:drawable="@drawable/yt_bg_press_btn_tire" android:state_pressed="true"/>
</selector>
相关推荐
贺biubiu1 天前
2025 年终总结|总有那么一个人,会让你千里奔赴...
android·程序员·年终总结
xuekai200809011 天前
mysql-组复制 -8.4.7 主从搭建
android·adb
nono牛1 天前
ps -A|grep gate
android
未知名Android用户1 天前
Android动态变化渐变背景
android
nono牛1 天前
Gatekeeper 的精确定义
android
stevenzqzq1 天前
android启动初始化和注入理解3
android
城东米粉儿1 天前
compose 状态提升 笔记
android
粤M温同学1 天前
Android 实现沉浸式状态栏
android
ljt27249606611 天前
Compose笔记(六十八)--MutableStateFlow
android·笔记·android jetpack