Android peferenceactivity A simple way to customize the title

Source: Internet
Author: User

Android peferenceactivity A simple way to customize the title

Peferenceactivity fully uses a well-defined layout.
So you can't simply customize it like other good windows, and now we need to add
A custom caption, such as adding a unified topbar like other windows.
Suppose the layout of this topbar is Title.xml

I. Standard custom title bar method

Android provides custom title bar methods
We are simple to implement.

@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 on Android 4.0 will prompt

You cannot combine custom titles with other title features

There are many complex solutions available online, and the key to perferenceactivtiy is always failure.

Two. Customize a perfence layout and act as the first configuration item.

Under the Xml/perference.xml layout file, add a

<preference android:layout= "@layout/title" android:key= "App_info"/>

In this way the pseudo-title bar can be implemented, the disadvantage of this method layout is not able to fill the entire window, that is, on both sides of the layout will be a white edge, very bad look.

Three. Build a custom window layout

In query data discovery, Perferenceactivity is able to support a fully customized layout, as long as the layout of a ListView is guaranteed, its ID is
Android:id= "@android: Id/list" can

In the call Addpreferencesfromresource (); , the Perference list is automatically added to the ListView. and the title layout, simply add one above the ListView can.

This is a successful layout and the effect is very satisfying.

<?xml version= "1.0" encoding= "Utf-8"?>

< LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" android:background= "@color/bg_color" >

<listview android:id= "@android: Id/list" android:layout_width= "Fill_parent" Android: layout_height= "Wrap_content" android:cachecolorhint= "@color/transparent" android:scrollbarstyle= "OutsideOverlay" Android:fadingedgelength= "0DP" android:scrollbars= "None" android:fadingedge= "None" android:listselector= "# 00000000 "/>
</linearlayout>

And this has the added benefit of being able to customize the background color of the Perference list.

Android peferenceactivity A simple way to customize the title

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.