I. Styles and themes (style and theme)
The 1.1 style is a collection of properties that specify the appearance and format of views and Windows. Styles can specify properties such as text, font and size, background color, and so on. Like what:
1 <Resources>2 3 <stylename= "Customfont">4 <item name= "Android:layout_width" >match_parent</item>5 <item name= "Android:layout_height" >wrap_content</item>6 <item name= "Android:textcolor" > #d05050 </item>7 <item name= "android:textsize" >16sp</item>8 <item name= "android:gravity" >center</item>9 </style>Ten One </Resources>
Styles are used in the TextView control:
1 < TextView 2 Android:id = "@+id/show_activity_id" 3 style= "@style/customfont"4 android:text= "Hello" />
1.2 Style inheritance
The style can inherit a current style through the Paren property, and then modify or add properties. Like what:
1 <Resources>2 3 <stylename= "Customfont">4 <item name= "Android:layout_width" >match_parent</item>5 <item name= "Android:layout_height" >wrap_content</item>6 <item name= "android:textsize" >16sp</item>7 <item name= "android:gravity" >center</item>8 </style>9 Ten <stylename= "Customfontcolor"Parent= "Customfont"> One <item name= "Android:textcolor" > #d05050 </item> A </style> - - </Resources>
Currently, when inheriting from a defined style, you can also not need the parent property, just precede the new style name with the name of the style that will be inherited, and use "." Between the names. Separated. Like what:
1 <Resources>2 3 <stylename= "Customfont.customfontcolor">4 <item name= "Android:textcolor" > #d05050 </item>5 </style>6 7 </Resources>
1.2 Setting themes for activity or application
To set the theme for Activity or application, in the Androidmanfest.xml file, in the <Activity> (or <Application>) tab, set up Android: The Theme property. Like what:
1 <Application2 Android:allowbackup= "true"3 Android:icon= "@mipmap/ic_launcher"4 Android:label= "@string/app_name"5 Android:supportsrtl= "true"6 Android:theme= "@style/apptheme">7 8 <Activity9 Android:name=". Activity.secondactivity "Ten Android:launchmode= "Singletop" One Android:theme= "@style/customttheme"/> A - </Application>
If the inherited system theme does not meet the requirements, you can also inherit the theme, modify or add attributes, as follows:
< Resources > < name= "Customttheme" parent= "@style/apptheme"> <item name= "Android:colorbackground" > #666 </item> </ style > </ Resources >
Android app and Activity theme configuration