The styles and CSS styles in Android are similar in that they are used to define the display style for an interface element, which is a collection that contains one or more view control properties. For example, you need to define the color and size of the font.
this is defined in CSS:
<style>
. Itcast{color: #0000CC; font-size:18px;}
</style>
You can use the above CSS style like this: <div class= "itcast" > Intelligence podcast </div>
In Android, you can define a style like this:
Add the following in the Res/values/styles.xml file
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<style name= "Itcast" > <!--define a globally unique name for the style-->
<item name= "Android:textsize" >18px</item> <!--the Name property is the property held by the View control to which the style is to be used-->
<item name= "Android:textcolor" > #0000CC </item>
</style>
</resources>
You can use the above Android style in the layout file as follows:
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android" ....>
<textview style= "@style/itcast"
.../>
</LinearLayout>
There is a parent attribute in the <style> element. This property allows the current style to inherit a parent style, and the current style can inherit to the value of the parent style. Of course, if the value of the parent style does not meet your needs, you can also modify it as follows:
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<style name= "Itcast" >
<item name= "Android:textsize" >18px</item> <!--the Name property is the property held by the View control to which the style is to be used-->
<item name= "Android:textcolor" > #0000CC </item>
</style>
<style name= "Subitcast" parent= "@style/itcast" >
<item name= "Android:textcolor" > #FF0000 </item>
</style>
</resources>
The Android theme is also used to define the display style for the application, and it has the same definition and style as the following:
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<style name= "Itcasttheme" >
<item name= "Android:windownotitle" >true</item> <!– no title à
<item name= "Android:windowfullscreen" >?android:windowNoTitle</item> <!– full-screen display à
</style>
</resources>
The question mark in the "? Android:windownotitle" above is used to refer to the values of resources defined in the current topic. The following code shows how to set the theme defined above for the application in Androidmanifest.xml:
Copy Code code as follows:
<application android:icon= "@drawable/icon" android:label= "@string/app_name"
Android:theme= "@style/itcasttheme" >
......
</application>
In addition to setting topics in Androidmanifest.xml, you can also set topics in your code, as follows:
Settheme (R.style.itcasttheme);
Although the styles and themes are basically the same on the definition, they are used in different places. Style used in individual View, such as: EditText, TextView, etc. the subject is used in the whole application or some activi through the <application> and <activity> in Androidmanifest.xml Ty, the subject has a global impact on the entire application or on an activity. If an application uses a theme, and the view that is applied also uses a style, the style takes precedence over the theme when the theme conflicts with the style attribute.
In addition, the Android system also defines a number of topics, For example: <activity android:theme= "@android: Style/theme.dialog" >, this topic lets the activity look like a dialog box, which you can view in the document's Referenceàandroid-->r.style if you need to review the topics.