我在哪里可以找到 android 中定义的颜色

Where can I find defined colors in android

我从默认模板底部导航创建了项目 Activity。我发现 BottomNavigationView 的背景颜色是深色主题的 #2D2D2D。我在 colors.xml 中定义了它,但我不确定它是否是好的解决方案。系统中是否有任何预定义的颜色(smth like @android:color/theColorThatINeed)?我在哪里可以看到所有这些?

最佳做法是使用 colors.xml,然后将所有颜色放在那里, 然后这样称呼它:

android:background="@color/red"

还有颜色的系统常量,其中包含以下常量: http://developer.android.com/reference/android/R.color.html

此资源是只读的,您不能向其中添加更多常量。

Is there any pre-defined colors in system?

有,但数量有限。这些颜色在 android.R.color 中定义。这是其中的一些。

background_dark
background_light
black
darker_gray
holo_blue_bright
holo_blue_dark
holo_blue_light
holo_green_dark
holo_green_light
holo_orange_dark
holo_orange_light
holo_purple
holo_red_dark
holo_red_light
transparent
white
widget_edittext_dark

要使用它们:

android:background="@android:color/background_dark"/>

遗憾的是,没有一个地方可以找到所有 'system colours'。您可以通过文档找到它们,这对于 material 组件(BottomNavigationView 的来源)通常很容易,或者通过拖网浏览源代码。对于您的特定示例,您所追求的颜色是 ?attr/colorSurface,它位于 documentation and the source code.