显示了在Android嵌套preferenceScreen /后退按钮? [英] Show up/back button on android nested PreferenceScreen?

查看:1677
本文介绍了显示了在Android嵌套preferenceScreen /后退按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个级别的preferenceScreen:

I have a two level PreferenceScreen:

<PreferenceScreen>
general settings
   <PreferenceScreen android:key="adv_settings">
   more advanced settings
   </PreferenceScreen>
</PreferenceScreen>

我的问题是,第二个屏幕不会自动显示在操作栏上的返回/向上按钮。如何让我的向上按钮出现在adv_settings?

My problem is that the second screen doesn't show the back/up button on the action bar automatically. How do I make the up button appear on adv_settings?

推荐答案

您可以通过编写自定义动作条的风格要与你的应用程序中使用的主题添加箭头。

You can add the arrow by writing a custom ActionBar style to be used with your application theme.

RES /值-V11 / styles.xml:(或添加到您现有的styles.xml)

res/values-v11/styles.xml: (or add these to your existing styles.xml)

<?xml version="1.0" encoding="utf-8"?>
<resources>    
  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
  </style>

  <style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
  </style>
</resources>

然后应用这一主题在你的Andr​​oidManifest.xml:

Then apply this theme in your AndroidManifest.xml:

<application android:theme="@style/MyTheme">



注意的:最明显的方式来增加这个箭头应该叫:

Note: The obvious way to add this arrow should be to call:

getActionBar().setDisplayHomeAsUpEnabled(true);

在第二个屏幕加载,但我觉得有一个Android臭虫getActionBar()总是返回一线动作条的对象,而不是一个当前可见,因此设置箭头动态失败。

once the second screen has loaded, but I think there's an Android bug where getActionBar() always returns the first-tier ActionBar object, as opposed to the one that is currently visible, so setting the arrow dynamically fails.

这篇关于显示了在Android嵌套preferenceScreen /后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆