Android Settings (System Setup) source analysis (a)

Source: Internet
Author: User
Tags home screen

due to the job requirements, some of the functions of the system settings are often used, such as the call of some screensavers, screen scaling, resolution, audio output mode and so on interface and data, so decided to Settings ( version: Android4.4.4) source code to do a rough analysis.

first on a regular interface, that is , the system setup (Settings) interface:

above is 4.2 version of, 4.4 and it's about the same.

Settings Source is located Android system Packages/apps directory, compiled by the system.

Locate the Settings androidmanifest. xml file and locate the program entry, such as:

Discover Settings 's startup class is Settings.java, such as:

can be seen, Settings inherited the preferenceactivity , about preferenceactivity , you can Google or reference API .

from the above Settings interface can be seen, the left is some tab, the right is the respective tab corresponding to the content.

Further discovery, The main interface layout of the Settings is loaded in the following places:

Locate the settings_headers.xml file in the resource file XML folder , and open the following :

          content more, only to intercept part of the code, you can see that the layout is using the preference Headers nested, left tab corresponding to the corresponding header header fragment

as for the updateheaderlist in the onbuildheaders (list method ( Headers) method What is the use of it? such as:

Find this method, such as:

The purpose of this is todecide whether to display the corresponding header based on whether the current platform supports a feature.

       Android 3.0after that, it abandoned the traditionalPreferencescreennested methods, instead of using the so-calledPreference Headersmethod, the main point of this method is: in the home screen through theHeaders XMLThe file layout lists all the theme settings, and the detailed settings for each theme are set by the respective specifiedpreferencefragmentresponsible, while the respectivepreferencefragmentcan be like the traditionalpreferenceactivitythe same way as the layout itselfPreferencescreen.

In addition, in order to be able to display the layout list in headers, you need to implement it in the inherited Preferenceactivity class. Onbuildheaders () callback method:

     @Override public     voidonbuildheaders (list

Advantages:

            suitable for use in devices of different screen sizes, for example, withPreference Headersafter the layout, the system settings are appliedPhoneand thePadin the display mode, respectivelydisplay for pagination and the same page;Headerscan reducePreferencelayout file Coupling degree, the original need to write in the sameXMLthe layout of the file is independent of each other and is controlled and maintained independently of each other.

Android Settings (System Setup) source analysis (a)

Related Article

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.