我正在开发一个应用,使用自定义的ImageView
来显示一张图片,并在其上放置一个边框。
目前边框的颜色是固定的黄色,但我认为如果能匹配系统按下按钮的颜色,比如Droid为橙色,Evo为绿色,Galaxy S为蓝色,那么效果会更好。
我查看了一些API文档,但没找到如何以编程方式获取这种颜色的方法。您有什么想法吗?
我正在开发一个应用,使用自定义的ImageView
来显示一张图片,并在其上放置一个边框。
目前边框的颜色是固定的黄色,但我认为如果能匹配系统按下按钮的颜色,比如Droid为橙色,Evo为绿色,Galaxy S为蓝色,那么效果会更好。
我查看了一些API文档,但没找到如何以编程方式获取这种颜色的方法。您有什么想法吗?
themes.xml
, styles.xml
, 和 colors.xml
源代码。从colors.xml中可以注意到没有定义很多颜色,这是因为大部分小部件都是通过9-patch文件完成的。 223 <style name="Widget.Button">
224 <item name="android:background">@android:drawable/btn_default</item>
225 <item name="android:focusable">true</item>
226 <item name="android:clickable">true</item>
227 <item name="android:textAppearance">?android:attr/textAppearanceSmallInverse</item>
228 <item name="android:textColor">@android:color/primary_text_light</item>
229 <item name="android:gravity">center_vertical|center_horizontal</item>
230 </style>
btn_default
Drawable
中完成。
< p > btn_default.xml源代码:
17 <selector xmlns:android="http://schemas.android.com/apk/res/android">
18 <item android:state_window_focused="false" android:state_enabled="true"
19 android:drawable="@drawable/btn_default_normal" />
20 <item android:state_window_focused="false" android:state_enabled="false"
21 android:drawable="@drawable/btn_default_normal_disable" />
22 <item android:state_pressed="true"
23 android:drawable="@drawable/btn_default_pressed" />
24 <item android:state_focused="true" android:state_enabled="true"
25 android:drawable="@drawable/btn_default_selected" />
26 <item android:state_enabled="true"
27 android:drawable="@drawable/btn_default_normal" />
28 <item android:state_focused="true"
29 android:drawable="@drawable/btn_default_normal_disable_focused" />
30 <item
31 android:drawable="@drawable/btn_default_normal_disable" />
32 </selector>
myTextView.setTextColor(getResources().getColor(android.R.color.holo_red_light));