Add buttons to PreferenceFragment

后端 未结 4 1990
野性不改
野性不改 2021-02-14 05:48

I want to add a couple buttons to the bottom of my preferences screen for setting defaults and restoring defaults. This answer doesn\'t cover how to do this using PreferenceFrag

4条回答
  •  迷失自我
    2021-02-14 06:09

    Just create your own layout for the settings activity which contains list view with id @android:id/list

    
    
    
        
            
        
    
        

    And then in the activity class set the content view before adding preference fragment

    public class SettingsActivity extends Activity {
    
        @Override
        public void onCreate( Bundle savedInstanceState) {    
            super.onCreate( savedInstanceState);
            setContentView(R.layout.settings_activity)
    
            // load up the preferences fragment
            getFragmentManager().beginTransaction().replace( android.R.id.content, new PrefsSettingsFragment()).commit();
        }
    }
    

提交回复
热议问题