Simple Method for customizing the title of Android peferenceActivity

Source: Internet
Author: User

Simple Method for customizing the title of Android peferenceActivity
Simple Method for customizing the title of Android peferenceActivity

PeferenceActivity fully uses the defined layout.
Therefore, it cannot be customized like other good windows. Now we need to add
A custom title, such as adding a uniform topbar like other windows.
Assume that the topbar layout is title. xml.

I. Standard custom title bar method

Android provides custom title bar Methods
We can simply implement it.

@ Override
Protected void onCreate (Bundle savedInstanceState ){
Final boolean isCustom = requestWindowFeature (Window. FEATURE_CUSTOM_TITLE );
Super. onCreate (savedInstanceState );
SetContentView (R. layout. tab_setting );
AddPreferencesFromResource (R. xml. setting_preference );

If (isCustom)
GetWindow (). setFeatureInt (Window. FEATURE_CUSTOM_TITLE, R. layout. title );

}

But in Android 4.0, a message is displayed.

You cannot combine custom titles with other title features

There are many complex solutions available on the Internet. The key is that PerferenceActivtiy always fails.

2. Customize a perfence layout and use it as the first configuration item.

Add

In this way, the pseudo title bar can be implemented. The disadvantage of this layout method is that the entire window cannot be filled, that is, there will be a white edge on both sides of the layout, which is very difficult to see.

3. Create a custom window layout

When querying data, we found that perferenceActivity supports full custom la S. To ensure a listView in the layout, its id is
Android: id = "@ android: id/list"

After addPreferencesFromResource (); is called, The perference list is automatically added to the listView. The title layout can be simply added to the listView.

This is a successful layout with very satisfactory results.





In addition, this will bring additional benefits: You can customize the perference list background color and so on.

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.