android-Style and Themes
the difference between a style and a theme theme
1. Theme is for window level, change window style
2. The style is for the window element level. Change the style of a specified control or layout
two ways to use style
1, create style
Create a styles.xml file under Res/values
Join node (root node)
Add your own defined style and its properties:
Format of Style
<style name="MyStyle" parent="指定的父style"
There is no need for Android in front of name:
<item name="ATTR须要设置的属性名">[VALUE设定的值]</>
The Parent property is optional and can inherit the properties of other style, while the existing style is
This value is very useful when changing.
Instance:
<style name="ChengzhiStyle"> <item name="android:textColor">#FFF0000</item></style>
2, specifying a style for the control
Specify in Layout:
<TextView style="@style/MyStyle"/>
Three Theme Theme
1, Usage:
In the manifest file, specify the theme attribute for the activity (this is the recommended way)
android:theme="@style/AppTheme">
Or, when activity is created, it calls the Settheme function (which must be called before Setcontentview. Not recommended for use)
@Override protectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置主题 setTheme(R.style.AppTheme); setContentView(R.layout.layout_portrait); }
2. Using the system's own theme
Frequently used systems theme for example with:
3, define yourself theme
<style name="MyTheme" [parent="继承的主题"] <item name="ATTR">[VALUE]</></style>
4, example of frosted glass effect
Frosted glass Effect: It is very much the interface of the first startup of the program, or the blurred activity interface behind the popup dialog box
@Override protectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置毛玻璃效果 getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); }
android-Style and Themes