我现在正在开发一个应用程序,它使用子类ImageView来显示一个带有边界框的图像.
现在,无论如何,盒子都以黄色绘制,但我认为如果颜色与系统的按钮按下颜色相匹配会更好看,例如Droid为橙色,Evo为绿色,Galaxy S为蓝色.
我查看了一下API,但找不到如何以编程方式获取该颜色.有任何想法吗?
你可以从android的,和themes.xml,看看来源.您从colors.xml中注意到的一件事是定义的颜色不是很多.这是因为大多数小部件都是通过9个补丁文件完成的.styles.xmlcolors.xml
按钮样式:
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>
Run Code Online (Sandbox Code Playgroud)
所有改变背景颜色的工作都是在.btn_default Drawable
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>
Run Code Online (Sandbox Code Playgroud)
其中每一个都是一个9补丁文件.问题是那些是pngs.颜色内置于图像文件中,不会在任何地方定义.正如您已经注意到这些图像可以被替换并且外观会发生变化.
不幸的是,你想要的是不可能的.你将不得不选择一种颜色.可能应选择此颜色以适合您的应用程序的其余部分.对不起:(
小智 8
从Android ICE_CREAM_SANDWICH(API 14),你有android.R.color中的主题颜色.*
例如;
myTextView.setTextColor(getResources().getColor(android.R.color.holo_red_light));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11181 次 |
| 最近记录: |