java - add ToolBar in Preference Activity? -


i have created app settings preferences. noticed, there no toolbar in preferenceactivity. how can add toolbar preferenceactivity?

public class settingsactivity extends preferenceactivity implements         preference.onpreferencechangelistener {      preferencemanager manager;     listpreference listpreference;     sharedpreferences sharedpreference;      @suppresswarnings("deprecation")     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         addpreferencesfromresource(r.xml.language_option_preference);         sharedpreference = preferencemanager.getdefaultsharedpreferences(this);          manager = getpreferencemanager();         listpreference = (listpreference) manager.findpreference("language_setting");          listpreference.setonpreferencechangelistener(this);     }      @override     public boolean onpreferencechange(preference preference, object newvalue) {          resources resource = getresources();         configuration config = resource.getconfiguration();          int pos = integer.parseint((string) newvalue);         if (pos == 1) {             sharedpreference.edit().putstring("language", "en").commit();             config.locale = locale.english;             listpreference.setvalue("1");         } else if (pos == 2) {             sharedpreference.edit().putstring("language", "zh").commit();             config.locale = locale.china;             listpreference.setvalue("2");         } else {             sharedpreference.edit().putstring("language", "auto").commit();             config.locale = locale.getdefault();             listpreference.setvalue("0");         }          getbasecontext().getresources().updateconfiguration(config, null);          intent intent = new intent();         intent.setclass(this, mainactivity.class);         intent.setflags(intent.flag_activity_clear_top);         this.startactivity(intent);         return false;     } } 

get appcompatpreferenceactivity , add project. then:

actionbar bar = getsupportactionbar(); if( bar != null ) {     // remove arrow     bar.setdisplayhomeasupenabled( false );     bar.setdisplayshowtitleenabled( true ); } 

i highly recommend read this article explaining how use preferences / preferencefragment.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -