【发布时间】:2011-03-31 05:39:45
【问题描述】:
当用户按下 ListView 项 (android:state_pressed="true") 时,它会闪烁黄色阴影(或者您可以按住)。
这是什么可绘制的?我创建了自己的选择器,因为我想要自己的 ListView 项目颜色,但我失去了按下的颜色。
有一个关于皮肤按钮的 Android 文档引用 #ffff0000,但这会产生红色。
有谁知道它是什么以及如何引用它?
【问题讨论】:
当用户按下 ListView 项 (android:state_pressed="true") 时,它会闪烁黄色阴影(或者您可以按住)。
这是什么可绘制的?我创建了自己的选择器,因为我想要自己的 ListView 项目颜色,但我失去了按下的颜色。
有一个关于皮肤按钮的 Android 文档引用 #ffff0000,但这会产生红色。
有谁知道它是什么以及如何引用它?
【问题讨论】:
颜色定义为#AARRGGBB,其中 AA 表示 alpha(透明度)值,RR 表示红色量,GG 表示绿色量,BB 表示蓝色量。因此#ffff0000 是实心的并且全是红色的。如果你想要橙色,你想添加一些绿色,即:#ffffA500。谷歌 RGB 颜色值以查看颜色页面及其 rgb 值。
【讨论】:
您所说的是 Android 操作系统的内置选择器。
在您的可绘制文件夹中使用 xml 文件制作您自己的高亮,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#YOURCOLOR" />
<item android:color="#FE896F" />
</selector>
然后在你的 XML 文件中有你的 ListView。
android:textColor="@drawable/highlight" //For text to appear like YOURCOLOR
//or if you wish the background
android:background="@drawable/highlight" //For the background to appear like YOURCOLOR
我希望就是这样,告诉我这是否有效!
【讨论】:
我在照片编辑应用程序中使用了颜色选择器工具来查找渐变的外部和内部颜色并自己制作。
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ffb300"
android:centerColor="#ffc800"
android:endColor="#ffb300"
android:angle="270"/>
</shape>
【讨论】:
默认系统资源可以在<android-sdk>/platforms/android-<version>/data/res中找到。特别是,列表选择器在drawable/list_selector_background.xml中定义:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@color/transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false"
android:state_pressed="true"
android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_enabled="false"
android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true"
android:drawable="@drawable/list_selector_background_focus" />
</selector>
在印刷机上显示的可绘制对象list_selector_background_transition 不是单一颜色,而是两个 9 色块图像,一个黄色和一个白色,它们之间有动画过渡。
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:drawable/list_selector_background_pressed" />
<item android:drawable="@android:drawable/list_selector_background_longpress" />
</transition>
【讨论】: