gpt4 book ai didi

android - 以编程方式获取主题颜色

转载 作者:IT老高 更新时间:2023-10-28 23:33:28 34 4
gpt4 key购买 nike

我现在正在开发一个应用程序,它使用子类 ImageView 来显示带有边界框的图像。

现在盒子无论如何都是用黄色绘制的,但我认为如果颜色与系统的按钮按下颜色匹配会更好看,例如 Droid 为橙色,Evo 为绿色,或蓝色为银河S。

我浏览了一下 API,但找不到如何以编程方式获取该颜色。有什么想法吗?

最佳答案

可以从android的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 中完成。 可绘制.

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>

每一个都是一个 9 补丁文件。问题是那些是png。颜色内置在图像文件中,没有在任何地方定义。正如您所注意到的,这些图像可以被替换并且外观会发生变化。

不幸的是,你想要的东西是不可能的。你将不得不选择一种颜色来搭配。应该选择此颜色以适合您的应用程序的其余部分。对不起:(

关于android - 以编程方式获取主题颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3375296/

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