14337

How to remove the title bar from PreferenceCategory in PreferenceActivity

This is my preferences xml file: myPreferences.xml:

<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory> <EditTextPreference android:key="name" android:title="Name" android:inputType="text" android:defaultValue="" /> <EditTextPreference android:key="email" android:title="Email" android:inputType="textEmailAddress" android:defaultValue="" /> <EditTextPreference android:key="phone" android:title="Phone Number" android:inputType="phone" android:defaultValue="" /> <EditTextPreference android:key="zipcode" android:title="Zip Code" android:inputType="number" android:defaultValue="" /> </PreferenceCategory> </PreferenceScreen>

This is my preferences activity declaration in my AndroidManifest.xml:

<activity android:name=".activities.MyPreferencesActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar" />

And, this is a style I have tried applying to my activity before:

<activity android:name=".activities.MyPreferencesActivity" android:screenOrientation="portrait" android:theme="@android:style/PreferenceTheme" /> <style name="PreferenceTheme"> <item name="android:background">@drawable/background_preferences</item> <item name="android:windowNoTitle">true</item> </style>

It doesn't work.

Then, I've tried doing it through java code in my onCreate of myPreferencesActivity:

@Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.myPreferences); }

Doesn't work. Tried setting the title to a drawable.

@Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_profile); getWindow().setFeatureDrawableResource(Window.FEATURE_CUSTOM_TITLE, R.drawable.profile_banner); }

NOPE. Doesn't work.

Everything I did only removes the title bar of the preference activity but not the preference category.

Could someone please help me? Thanks in advance.

Answer1:

If you don't want to have a title bar above a group of preferences, don't use a PreferenceCategory as it is serving no purpose, and just put all your preferences into the PreferenceScreen element:

<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <EditTextPreference android:key="name" android:title="Name" android:inputType="text" android:defaultValue="" /> <EditTextPreference android:key="email" android:title="Email" android:inputType="textEmailAddress" android:defaultValue="" /> <EditTextPreference android:key="phone" android:title="Phone Number" android:inputType="phone" android:defaultValue="" /> <EditTextPreference android:key="zipcode" android:title="Zip Code" android:inputType="number" android:defaultValue="" /> </PreferenceScreen>

HTH

Recommend

  • Partial UI screen up
  • Moving focus from one EditText to another
  • C# 6 bool and new null check with ? what to return back
  • Swift where condition to check if a property is implemented
  • Outlook 365 add-in only appears in Outlook 2013 client
  • Get users zipcode using facebook javascript api
  • Jquery autocomplete with php as remote source: how to append second variable from input to source
  • Insert multiple values into hidden field
  • onFocus and onBlur
  • Operation not supported on read-only collection
  • Add delivery info to query in SAP Crystal Reports
  • adb device not listed for Gionee E7 mini
  • Storing WCF rest request data with SQL Server stored procedure
  • How to clip image to ellipse in XAML
  • Retrieving a contacts notes
  • Installing apk from within application in android
  • How to merge two Request in Laravel
  • Encrypting credit card details using AngularJS in Braintree
  • Unique SMS sender id?
  • CoreData basics – to-many relationship array data
  • Eloquent Relationship on Partial Match
  • How to access recipient on sent messages page with mailboxer
  • Dynamically set LESS variables from user settings
  • testing a POST using phpunit in laravel 4
  • XMLBeans Duplicate Class and Class Not Found Errors
  • 550 Access denied - Invalid HELO name
  • Login not working in Firefox in Meteor
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • How do I access an unhandled exception in an MVC Error view?
  • Email verification using google app script and google forms
  • Email format validation in mvc3 view
  • Is there a javascript serializer for JSON.Net?
  • MySQL WHERE-condition in procedure ignored
  • Where to put my custom functions in Wordpress?
  • sending/ receiving email in Java
  • Web-crawler for facebook in python
  • Buffer size for converting unsigned long to string
  • trying to dynamically update Highchart column chart but series undefined
  • Binding checkboxes to object values in AngularJs
  • java string with new operator and a literal