Home > Blockchain >  Where can I find defined colors in android
Where can I find defined colors in android

Time:10-25

I've created the project from default template Bottom Navigation Activity. I found that the background color for BottomNavigationView is #2D2D2D for dark theme. I defined it in colors.xml, but I'm not sure that it's good solution. Is there any pre-defined colors in system(smth like @android:color/theColorThatINeed)? Where can I see all of them?

CodePudding user response:

Unfortunately there isn't a single place to find all the 'system colours'. You can either find them through documentation, which is usually easy with the material components (which is where BottomNavigationView is from, or by trawling through the source code. For your particular example the colour you're after is ?attr/colorSurface, which is in the documentation and the source code.

CodePudding user response:

the best practice is to use colors.xml, and put there all of your colors, and then call it like this:

android:background="@color/red"

there are also system constants for colors, which contains this constants: http://developer.android.com/reference/android/R.color.html

this resources are read only and you can not add to them more constants.

CodePudding user response:

You can get android system color using:

android:background="@android:color/black"

Or you can simply use color resources, specified usually inside res/values/colors.xml :

<color name="bottomnav">#2D2D2D</color>

and use like this:

android:background="@color/bottomnav"

CodePudding user response:

Is there any pre-defined colors in system?

Yes, there is but it's limited. These colors are defined in android.R.color. Here are some of them.

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

To use them:

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