|
I spent quite a while trying to find this info and I often forget things, so I'm putting it here so I can find it again easily and hopefully others will find this useful.
My project was pretty simple. The ListView I was creating wasn't very complicated. I wasn't looking to customize it with multiple columns, images, or anything of the sorts. I just wanted to change the color of the text so I could see it against my background. And Android doesn't provide a simple way to do this. Actually...there is a simple way to do it, but it's not intuitive.
The solution is actually pretty simple. All you have to do is create an XML file in your res/values directory of your project. The name of the XML file is arbitrary, but it should look something like this:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="BlackText"> <item name="android:textColor">#000000</item> </style> </resources>
This is akin to a stylesheet in HTML/CSS web development. It can be applied to specific views (i.e. a ListView), an Activity, or an entire Application, much the same way stylesheets can be applied to specific page elements using style="", an entire page using <style></style> or linked on every page of the site using <link/>.
The way you apply it to an entire application is to open the AndroidManifest.xml, look for your <application> tag, and add android:theme="@style/BlackText" (note that my <style> tag above has a name="BlackText" attribute, which is what is used in the android:theme="" attribute).
The way you apply this style to a specific Activity, add the android:theme="BlackText" attribute to the <activity> tag of your choice in your AndroidManifest.xml file.
To apply it to a specific view, add a style="@style/BlackText" attribute to the view tags (i.e. <TextView>) of your choice in any of your layout XML files you have.
That's it. Enjoy!
For more information see: Applying Styles and Themes | Android Developers. |