Styles and themes in Android app development (Style,themes)
More and more Internet companies are deploying their clients on the Android platform, and in order to improve the user experience, these clients are well-laid and aesthetically pleasing .... Android's style design is one of the keys to improving the user experience. The style on Android is divided into two areas:
- 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/windowtitlebackground</item>
<item name= "Android:windowanimationstyle" > @android:style/animation.activity</item>
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 a style, the theme is still 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 the theme in Manifest 1. In order to be 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 definition in manifest is as follows: <activity android:theme= "@android: Style/theme.dialog" > (see the previous 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.
<style name= "Customdialogtheme" 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.
===============================================================================
Examples can be seen:
1.http://wang-peng1.iteye.com/blog/561292 android Buttonbar Design--style Reference
2.http://mycoding.iteye.com/blog/966726 Android with style simplifies layout layouts file
Styles and themes in Android app development (Style,themes) (RPM)