当用户按下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
al。 TypeWriter
中的LinearLayout
:
<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>
项目文件夹结构:
颜色总是棕色。任何的想法?我首先想到它可能是不正确的文件夹结构,但棕色的颜色工作。
构建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'
}
}
}
}
答案 0 :(得分:1)
尝试仅使用这些
<selector xmlns:android="http://schemas.android.com/apk/res/android"
<item android:state_pressed="false" android:color="@color/main_menu_text_brown" />
<item android:state_pressed="true" android:color="@color/main_menu_text_battle_mode_on" />
<item android:color="@color/main_menu_text_brown" />
</selector>