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.