Android peferenceActivity custom title simple method, android custom title

Source: Internet
Author: User

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
 

Related Article

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.