Register your own theme in the Style.xml
<name="Mytext" >
<name="android:textsize" >18sp</item>
<name="Android:textcolor" > #ff99 </item>
</style>
Referencing in other files
<Listview
android: Layout_width= android: Layout_height= style= "@ Style/mytext "
></listview>
Reprint: http://zyfromcq.iteye.com/blog/1401710
- Theme is for the form level, change the form style;
- Style is for the level of the form element, changing the style of the specified control or layout.
The Android system's Themes.xml and Style.xml (located in \base\core\res\res\values\) contain a number of system-defined style, suggesting that you pick a suitable one and then inherit the changes.
The following properties are common in themes and originate from the Themes.xml of the Android system itself:
<!--Window attributes- <Item Name="Windowbackground">@android:d rawable/Screen_background_dark</Item> <Item Name="Windowframe">@null</Item> <Item Name="Windownotitle">False</Item> <Item Name="Windowfullscreen">False</Item> <Item Name="Windowisfloating">False</Item> <Item Name="Windowcontentoverlay">@android:d rawable/Title_bar_shadow</Item> <Item Name="Windowtitlestyle">@android: Style/WindowTitle</Item> <Item Name="Windowtitlesize">25dip</Item> <Item Name="Windowtitlebackgroundstyle "> @android: style< Span style= "color: #000000;" >/windowtitlebackground</ item> <item name= "android:windowanimationstyle "> @android: Style/animation.activity</item> Copy Code
Various styles specific use can be seen: http://henzil.easymorse.com/?p=364 Android Theme use summary
As far as the control's style design is, look at the Eclipse's Android control property editor [properties] to know what the entries are , and Android built-in Style.xml just defines the default style for each control .... However, the style of the control does not suggest a big change, the engaging style allows users to use the software for a long time. In addition, the style of the control in many cases to use the 9.png, learning 9.png must go to the \base\core\res\res\drawable-hdpi inside to see, there are many systems built-in 9.png.
Both style and theme are resources. You can use some of the default style and theme resources provided by Android, and you can customize your own style and theme resources.
How to create a new custom style and theme:
1. Create a new file named Style.xml in the Res/values directory. Add a <resources> root node.
2. For each style and theme, add a globally unique name to <style>element, and optionally add a parent class attribute. In the back we can use the name to apply the style, and the parent attribute identifies which style the current style is inherited from.
3. Within the <style> element, affirm one or more <item> Each of the <item> defines a name attribute and defines the value of the style within the element.
4. You can apply resources that are defined in other XML.
Style:
Below is an example of a statement style:
<?xml version= "1.0" encoding= "Utf-8"?><resources> <style name= "Specialtext" parent= "@style/text" > <item name= "android:textsize" >18sp</item> <item name= "Android:textcolor" > #008 < /item> </style></resources>
As shown above, you can use the <item> element to define a set of formatted values for your style. The property of the name in item can be a string, a color represented by a 16 binary number, or a reference to another resource.
Note the parent class property in the <style> element. This property allows you to define a resource, and the current style can be inherited from this resource to a value. You can inherit this style from any resource that contains this style. In general, your resources should inherit the standard style resources of Android directly or indirectly. In this case, you just need to define the values you want to change.
In this example, the EditText element demonstrates how to refer to a style defined in an XML layout file:
<edittext id= "@+id/text1" style= "@style/specialtext" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:text= "Hello, world!"/>
Now the style shown in this EditText component is what we defined in the XML file above.
Theme:
Like style, the theme is still stated in the <style> element and is quoted in the same way.
The difference is that you add the theme to the entire program or to an activity by using the <application> and <activity> elements defined in Android manifest However, the theme cannot be applied to a single view.
Below is an example of a stated theme:
<?xml version= "1.0" encoding= "Utf-8"?><resources> <style name= "Customtheme" > <item name= " Android:windownotitle ">true</item> <item name=" Windowframe "> @drawable/screen_frame</item > <item name= "Windowbackground" > @drawable/screen_background_white</item> <item name= " Panelforegroundcolor "> #FF000000 </item> <item name=" Panelbackgroundcolor "> #FFFFFFFF </item > <item name= "Paneltextcolor" >?panelForegroundColor</item> <item name= "Paneltextsize" >14</item> <item name= "Menuitemtextcolor" >?panelTextColor</item> <item name= " Menuitemtextsize ">?panelTextSize</item> </style></resources>
Notice we used the @ symbol and? Symbol to apply the resource. The @ symbol indicates that the resources we have applied are defined previously (either in the previous project or in the Android framework). Question mark? Indicates that the value of the resource we are referencing has been defined in the current topic. You can do this by referencing the name defined in <item> (
PaneltextcolorUse the color and
as defined in the Panelforegroundcolor)。 This technique can only be used in XML resources.
set Theme (theme):
1. Set Themes in manifest
1. For in-use
all the ActivityUsing themes, you can open the Androidmanifest.xml file,
Editor <application>
label, let it contain the Android:theme attribute, and the value is the name of a subject, as follows:
<application android:theme= "@style/customtheme" >
2. If you just want to get your program
an activityWith this theme, then you can
Edit <activity> Label。
There are several built-in resources available in Android, and there are several themes you can switch to without writing on your own. For example, you can use a dialog box theme to make your activity look like a dialog box. The following are defined in manifest:<activity android:theme= "@android: Style/theme.dialog" >(see the front link for a lot of theme)
Add:
If you like a theme, but want to make some minor changes, you just need to add the theme as a parent topic. For example, we modify the Theme.dialog theme. Let's inherit theme.dialog to generate a new theme.
Parent= "@android: Style/theme.dialog" >
After inheriting the Theme.dialog, we can adjust the theme according to our requirements. We can modify the value of each item element defined in Theme.dialog, and then we use Customdialogtheme instead of Theme.dialog in the Android Manifest file.
2. Set the theme in the program
If necessary, you can load a theme in the activity by using the method Settheme (). Note that if you do this, you should initialize any view before setting the theme. For example, before calling the Setcontentview (View) and inflate (int, viewgroup) methods. This ensures that the system applies the current theme to all UI interfaces. Examples are as follows:
protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); .... SetTheme (Android. R.style.theme_light); Setcontentview (r.layout.linear_layout_3);}
If you intend to load the theme of the main interface in your program code, be aware that the theme does not include any animations that the system uses to initiate the activity, which will be displayed before the program starts. In many cases, if you want to apply a theme to your main interface, it seems like a better way to define it in XML.
Settings for theme in Android