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