【问题标题】:Where can I find defined colors in android我在哪里可以找到android中定义的颜色
【发布时间】:2021-12-10 16:51:33
【问题描述】:
我已经从默认模板底部导航活动创建了项目。我发现 BottomNavigationView 的背景颜色是 #2D2D2D 用于深色主题。我在colors.xml 中定义了它,但我不确定它是否是一个好的解决方案。系统中是否有任何预定义的颜色(例如@android:color/theColorThatINeed)?我在哪里可以看到所有这些?
【问题讨论】:
标签:
android
android-studio
material-design
【解决方案2】:
不幸的是,没有一个地方可以找到所有“系统颜色”。您可以通过文档找到它们,这通常很容易使用材料组件(这是BottomNavigationView 的来源),或者通过搜索源代码。对于您的特定示例,您所追求的颜色是?attr/colorSurface,它位于documentation 和source code 中。
【解决方案3】:
系统中有预定义的颜色吗?
是的,有,但数量有限。这些颜色在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"/>