android-Style and Themes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.