Android Settings UI Chapter

Source: Internet
Author: User

How is the Android Setup interface defined?

A: The main interface of the Android system setup is Settings.java, which is defined as:

At the same time we look at Settings.java's OnCreate function:

There doesn't seem to be a way to call Setcontentview, so how does the Setup interface appear? Let's go to its parent class (preferenceactivity) and look at the OnCreate method for this class:

As we can see, the originally set interface is defined as the Preference_list_content.xml in the framework.

By looking at the Preference_list_content.xml file we know that the structure of the layout is left and right, a ListView on the left, and a preferenceframelayout on one side.

But we have to pay attention to the right side of the android:visibility for gone, why? This is because the display is based on the size of the screen to adapt, if the screen is large enough such as smart TV or pad, is left and right structure, if it is a mobile phone, only display the left side of the ListView, the content needs to be displayed separately. So how do we tell if the screen should show the left and right structures? This is done in Preferenceactivity.java with the function to judge:

That is, read from the resource file, so let's see how this resource file is defined.

That is to say preferenceactivity to read the Preference_prefer_dual_pane property in the framework, if the return is true is a large screen device, otherwise it is a small screen.

Second, then the contents of the left-hand list is how to load it?

A: In the need to display the list, preferenceactivity OnCreate will call onbuildheaders method to load the contents of the list, first Settings.java rewrite the Onbuildheaders method, the method is defined as follows:

/**

* Populate the activity with the top-level headers.

*/

@Override

public void Onbuildheaders (list

if (!onishidingheaders ()) {

Loadheadersfromresource (r.xml.settings_headers, headers);

Updateheaderlist (headers);

}

}

The method calls the Loadheadersfromresource method in Preferenceactivity.java, which is parsing the XML file and saving the parsed header list to headers, and the parsed code is omitted. Now let's look at the definition of the Settings_headers.xml file.

After parsing and saving to headers, Settings.java calls the Updateheaderlist method to update the list. After the update is loaded into the ListView, which used a headeradapter this inner class, the function of this inner class is to load the contents of headers into the ListView, where the header is 4 categories, One is a switch (Header_type_switch such as WiFi), one is the total classification (header_type_category such as more), one is normal (Header_type_normal), There is also a button-type (Header_type_button). See details:

The Setlistadapter method is defined in Settings.java, and the parent class is called in the OnCreate method to display the contents of the list.

Third, how to do click on the item to jump to the corresponding fragment it?

When you click on item in the ListView, the Onlistitemclick in Preferenceactivity.java is processed,

This function calls the Onheaderclick function,

This function for different configuration to do different processing, if the single is a small screen is called startwithfragment method, if it is a large screen call Switchtoheader function If fragment in the header is null and header.intent is not empty, startactivity is called.

Four, for small screen devices, click on the item is how to switch to the next interface?

According to the 3rd we know that when it is a small screen device, clicking on item will call the Startwithfragment function, as follows:

Next look at the definition of onbuildstartfragmentintent:

Five, for large-screen devices, click on the item is how to switch to the next interface?

According to the 3rd we know that when a small screen device, click on item will call Switchtoheader (header); functions are as follows:

Conclusion:

The UI part of the Android system setup is roughly learned here, and overall it is the layout of the interface, the load of the ListView, the parsing and initialization of the headers, and the item click event of the ListView.

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.