gpt4 book ai didi

android - 在选择器不起作用的情况下更改按下时 TextView 的颜色

转载 作者:行者123 更新时间:2023-11-30 02:08:10 28 4
gpt4 key购买 nike

当用户按住 TextView 区域时,我正在尝试实现从棕色到绿色的颜色变化。

我的选择器代码(位于 res/color 文件夹中):

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@color/main_menu_text_battle_mode_on"/>
<item android:state_pressed="true" android:state_enabled="false" android:color="@color/main_menu_text_battle_mode_on" />
<item android:state_enabled="false" android:color="@color/main_menu_text_battle_mode_on" />
<item android:color="@color/main_menu_text_brown"/>
</selector>

我的 TextView 等。 LinearLayout 中的 TypeWriter:

<model.TypeWriter
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/endAllBattles"
android:duplicateParentState="true"
android:text="End all battles"
android:textColor="@color/main_menu_text_color_selector"
android:enabled="true"
android:clickable="true"
android:focusable="true" />

颜色 styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="main_menu_text_brown">#653823</color>
<color name="main_menu_text_battle_mode_on">#005500</color>
</resources>

项目文件夹结构:

enter image description here

颜色始终为棕色。任何想法?我首先认为它可能是不正确的文件夹结构,但棕色有效。

构建Build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.parse'

buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.parse.com/repo' }
}
dependencies {
classpath 'com.parse.tools:gradle:1.+'
}
}

dependencies {
compile 'com.parse.bolts:bolts-android:1.2.0'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile fileTree(dir: 'libs', include: 'ParseCrashReporting-*.jar')
compile fileTree(dir: 'libs', include: 'gson-2.3.1.jar')

}

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}

buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro', 'proguard-rules-new.pro'
}
}

}
}

最佳答案

尽量只使用这些

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/main_menu_text_brown" android:state_pressed="false" />
<item android:color="@color/main_menu_text_battle_mode_on" android:state_pressed="true" />
<item android:color="@color/main_menu_text_brown" />
</selector>

关于android - 在选择器不起作用的情况下更改按下时 TextView 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30442798/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com