Android programming is driving me crazy. The XML or programmable ways for GUI development is making a right old dogs breakfast of the code--some stuff here, some stuff there.
My current frustration is trying to keep it all XML and I would like to set the background color of the TextView
the same color as the background color of a Button
without having to specify the exact color code. I would like to use a system constant, something like java.awt.SystemColor.control
, but specified in XML.
Is there anyway of doing this without having to respecify a bunch of stuff? I'm looking for a solution like: android:background="{Insert constant here}"
.
red(int) to extract the red component. green(int) to extract the green component. blue(int) to extract the blue component.
The official Android color is green.
The primary color is the color displayed most frequently across your app's screens and components. The primary variant color is used to distinguish two elements of the app using the primary color, such as the top app bar and the system bar. The secondary color provides more ways to accent and distinguish your product.
The one most important to Android is sRGB. Before Android Oreo, applications used the sRGB color space. There's a reason for this — low-end hardware. Displaying a wide color gamut takes more GPU and CPU power than the sRGB space.
You should have a file in res/values called colors.xml, it should look like this:
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="white">#FFFFFF</color> <color name="grey">#7A7A7A</color> <color name="background">#0044AA</color> <color name="bluelight">#449DEF</color> <color name="bluedark">#2F6699</color> <color name="greenlight">#70C656</color> <color name="greendark">#53933F</color> <color name="orangelight">#F3AE1B</color> <color name="orangedark">#BB6008</color> <color name="black">#000000</color> </resources>
Then you can just call the color in xml like this:
android:background="@color/greenlight"
You can use things like "@color/white", or for android system constants, "@android:color/holo_red_light". Alternatively if you want more control, you can always define a common background in a drawable and set the background to "@drawable/mydrawable"
List of resources available for android:color here (like background_dark): http://developer.android.com/reference/android/R.color.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With