Android peferenceActivity custom title simple method, android custom title
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
<Preference android: layout = "@ layout/title" android: key = "app_info"/>
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.
<? 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">
<Include android: id = "@ + id/title" layout = "@ layout/title"> </include>
<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>
In addition, this will bring additional benefits: You can customize the perference list background color and so on.
In android development, how does one center the title, not a custom title? That is to say, xml is not required? If you can, paste the following method:
In the source code environment, you can modify the default Title layout file (screen_title.xml, etc.
It cannot be implemented in a non-source environment.
How to customize the title bar in android Development
Blog.csdn.net/..715678
The simplest way