How to use Color Resources in android Development
This article mainly explains "how to use color resources in android development", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use color resources in android development" bar!
Define an Android project named "Chapter03_Resource". In the project's resvalues directory, define a colors.xml color resource file, as shown below.
# f00
# 0000ff
Define a layout resource file under the reslayout directory of the project, add a TextView view component to the file, reference the color resource, and set the text color of the view component TextView to blue.
Define a TestColorActivity class, reference the color resource file, and set the background color to red.
Package com.amaker.ch03.color
Import android.app.Activity
Import android.os.Bundle
Import com.amaker.test.R
Public class TestColorActivity extends Activity {
@ Override
Public void onCreate (Bundle savedInstanceState) {
Super.onCreate (savedInstanceState)
SetContentView (R.layout.test_color)
/ / reference the color resource and set the background color to red
GetWindow () setBackgroundDrawableResource (R.color.red_bg)
}
}
Thank you for your reading, the above is the content of "how to use color resources in android development". After the study of this article, I believe you have a deeper understanding of how to use color resources in android development. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!