2011-04-09

Customize the layout of PreferenceActivity

In my application, I'd like to have non-Preference items shown on a PreferenceActivity like the TimePicker widget below,


Actually, it is easy to get this. The PreferenceActivity sets its content view to a ListView with list as its view id.
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(com.android.internal.R.layout.preference_list_content);
        
        mPreferenceManager = onCreatePreferenceManager();
        getListView().setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    }
and this preference_list_content is just a ListView,

which can be replaced by your own layout xml file as long as it contains one ListView with android:id/list as its id. You can put as many widgets as you want in this layout xml file and use setContentView() to use it in your onCreate() method.