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>
相关推荐
k***459920 小时前
MySQL----case的用法
android·数据库·mysql
r***86981 天前
Plugin ‘mysql_native_password‘ is not loaded`
android·数据库·mysql
v***59831 天前
MySQL-mysql zip安装包配置教程
android·mysql·adb
不用89k1 天前
Android无法区分USB摄像头是哪一个
android
ljt27249606611 天前
Compose笔记(五十七)--snapshotFlow
android·笔记·android jetpack
花阴偷移1 天前
kotlin语法(上)
android·java·开发语言·kotlin
Smart-佀1 天前
Android初学必备:选Kotlin 还是Java ?
android·android studio·安卓
普通网友1 天前
Android kotlin Jetpack mvvm 项目
android·开发语言·kotlin
大耳猫1 天前
Android Kotlin 协程详解
android·kotlin·协程
Crogin1 天前
快速简单入门Kotlin——基础语法(第一天)
android·开发语言·kotlin