kao*_*ick 6 xml navigation android preferencescreen android-actionbar
我有一个现代的SettingsActivity使用PreferenceFragement.我完全用XML定义了它的布局.在我的设置中,我有一个偏好子屏幕.点击它PreferenceScreen会显示一个新的.
因为看起来我只能使用后退按钮导航回主设置屏幕.有没有办法ActionBar在子屏幕中启用导航?我更喜欢通过XML启用它.
在此先感谢,高粱
编辑:
我想在右侧像左侧一样:

以下是Google的相应代码段:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!-- opens a subscreen of settings -->
<PreferenceScreen
android:key="button_voicemail_category_key"
android:title="@string/voicemail"
android:persistent="false">
<ListPreference
android:key="button_voicemail_provider_key"
android:title="@string/voicemail_provider" ... />
<!-- opens another nested subscreen -->
<PreferenceScreen
android:key="button_voicemail_setting_key"
android:title="@string/voicemail_settings"
android:persistent="false">
...
</PreferenceScreen>
<RingtonePreference
android:key="button_voicemail_ringtone_key"
android:title="@string/voicemail_ringtone_title"
android:ringtoneType="notification" ... />
...
</PreferenceScreen>
...
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
首先添加getActionBar().setDisplayHomeAsUpEnabled(true);到onCreate().
然后尝试:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(android.R.id.home == item.getItemId() ){
// try one of these:
// dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
// getFragmentManager().popBackStack();
// finish();
return true;
}
return super.onOptionsItemSelected(item);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4004 次 |
| 最近记录: |