1.Applying and writing styles(example:)
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyCustomTextView" parent="@android:style/Widget.TextView">
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#CCC</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:padding">5dip</item>
</style>
</resources>
acitivity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:text="Hello, text view!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/MyCustomTextView"
/>
the style attribute is global and not defined under the android XML namespace.
2.Applying and writing themes
The style and theme definition file for the MyMovies application:
values\styles.xml
3.Styling ListView backgrounds
example:
<resources>
...
<style name="MyMoviesListView" parent="@android:style/Widget.ListView">
<item name="android:background">#A000</item>
<item name="android:cacheColorHint">#0000</item>
...
</style>
</resources>
android:cacheColorHint ell Android which color it should use as the hint color.
if you were to change the default text style to bold red across your entire application, you could do this:
<style name="MyTheme">
<item name="android:textAppearance">@style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance">
<item name="android:textColor">#F00</item>
<item name="android:textStyle">bold</item>
</style>
set your application’s link color to the default text color, you could do this:
<style name="MyTheme">
<item name="android:textColorLink">?android:attr/textColorPrimary</item>
</style>
4.mymovies.project
values\styles.xml
values/colors.xml
<resources>
<color name="list_background">#A000</color>
</resources>
list_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@drawable/list_item_default" />
<item android:state_pressed="true" android:drawable="@drawable/list_item_pressed" />
</selector>
list_selector_default.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#AFFF" android:endColor="#FFFF" android:angle="0" />
<stroke android:color="#CCC" android:width="1dip" />
<corners android:radius="5px" />
</shape>
list_selector_press.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#AA66CCFF" android:endColor="#FFFF" android:angle="0" />
<stroke android:color="#CCC" android:width="1dip" />
<corners android:radius="5px" />
</shape>