How do I call a specific PreferenceFragment from a PreferenceActivity?

人盡茶涼 提交于 2019-11-29 03:52:12

According to: http://developer.android.com/reference/android/preference/PreferenceActivity.html#EXTRA_SHOW_FRAGMENT

public static final String EXTRA_SHOW_FRAGMENT

Added in API level 11 When starting this activity, the invoking Intent can contain this extra string to specify which fragment should be initially displayed.

Constant Value: ":android:show_fragment"

intent = new Intent( this, SettingsActivity.class );
intent.putExtra( PreferenceActivity.EXTRA_SHOW_FRAGMENT, Fragment1.class.getName() );
intent.putExtra( PreferenceActivity.EXTRA_NO_HEADERS, true );

Just use below code in your PreferenceActivity and PreferenceFragment in onCreate

addPreferencesFromResource(R.xml.**YOUR PREFERENCE FRAGMENT XML**);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!