Android topic customization and Modification

Source: Internet
Author: User

Android topic customization and Modification

Introduction: when writing Android apps, We reference a large number of Layout components and styles in xml files in Layout. Sometimes the native components provided by Android cannot meet our needs, in this case, we should consider customizing and modifying the style and theme.

Principles of layout files:
Each control in Layout contains a Button, such as TextView, EditText, And Button, in the directory frameworks/base/core/java/android/widget. java file, in the Button. java code:
Public Button (Context context, AttributeSet attrs ){
This (context, attrs, com. android. internal. R. attr. buttonStyle );
}
Public Button (Context context, AttributeSet attrs, int defStyle ){
Super (context, attrs, defStyle );
}
The layout control in layout is the referenced Button. java Control. When the App is compiled, it automatically references and associates with the corresponding control definition. The first constructor is the default style of the Button, and the second one selects the desired style based on the style written by the app. the Button is inherited from TextView. java, the constructor in this file will see the selection process. This constructor is a very large function.

Button. java has referenced related styles and themes, for example, in the Button. java references the buttonStyle style. in layout, you can add this style to the Button control, all style definitions are in the framework. In frameworks/base/core/res/values/themes_device_defaults.xml, there are theme names for all styles, these styles are defined in the frameworks/base/core/res/values/styles_device_defaults.xml file, and all attributes of a style can be obtained by extending the Item.

This definition exists in styles. xml:
<Style name = "Widget. DeviceDefault. Button" parent = "Widget. Holo. Button">
</Style>
The Widget here. deviceDefault. the Button is inherited from the Widget. holo. button, here the Widget. holo. the Button style has widgets. holo. all properties and functions of the Button control are similar to class inheritance here. If widgets are not required. holo. some items of the Button control can be rewritten,
<Style name = "Widget. DeviceDefault. Button" parent = "Widget. Holo. Button">
<Item name = "android: textColor"> @ android: color/XXX </item>
</Style>
Then, the android: textcolor is rewritten. Here, XXX can be defined in an xml file and the corresponding color value can be written. Because it has been modified in the framework, all controls referenced in the app will be modified. If you do not want this control to work in all apps, You can override it in the app. Write the style in the xml file in layout of an app. This app only works.

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.