preferenceActivity和主题不适用不适用、主题、preferenceActivity

2023-09-04 03:27:11 作者:江湖同醉

大家好,我设置了主题清单文件中是这样的:

Hi all I have set the theme in the manifest file like this:

android:theme="@android:style/Theme.Light"

但我在preferences活动的一个问题,在主preferences主题显示正常,但如果我得到一个子preference,主题就会变得混乱,这不是白它应该,这是所有的黑暗,而且字体是黑色的,所以你看不到太多,当我开始点击任何物品,他们将获得白色,有时,他们应该,但不久后回复到黑色。这仅仅是发生在2.1,同时在实际设备和仿真。测试在模拟器上运行1.6和它正常工作。这里是preferences xml文件的code部分:

But I have a problem in the Preferences Activity, in the main preferences the theme shows ok, but if I get to a sub preference, the theme gets messy, it is not white as it should, it is all dark, and the font is black so you can't see much, and when I start clicking on any items they will get sometimes white as they should but revert to black soon after. This is only happens on 2.1, in both the real device and emulator. Tested on the emulator running 1.6 and it was working correctly. Here is part of the code of the preferences xml file:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceScreen
        android:title="@string/account">
        <CheckBoxPreference
            android:key="enable_account"
            android:title="@string/account_use"
            android:summary="@string/account_summ" />
        <EditTextPreference
            android:key="username"
            android:title="@string/login"
            android:dependency="enable_account"
            android:summary="@string/login_summ" />
        <EditTextPreference
            android:key="password"
            android:title="@string/password"
            android:dependency="enable_account"
            android:summary="@string/password_summ"
            android:password="true" />
    </PreferenceScreen>

下面是截图:

And here is a screenshot:

任何变通办法?

推荐答案

有人刚刚发布一个替代方法http://$c$c.google.com/p/android/issues/detail?id=4611

Somebody just posted a workaround at http://code.google.com/p/android/issues/detail?id=4611

在简单地说,顶层preference屏幕似乎认识到了这个主题,但嵌套的人不是。因此,解决方法建议创建顶级preferenceActivity嵌套preferenceScreen,然后通过意向调用这个新的活动:

In a nutshell, top level preference screens seem to recognize the theme but nested ones not. So the workaround recommends creating top level PreferenceActivity for nested PreferenceScreen and then invoking this new activity via intent:

<PreferenceScreen android:key="key1"
                      android:title="1 Item"
                      android:summary="">
        <intent android:action="android.intent.action.VIEW"
                android:targetPackage="com.example"
                android:targetClass="com.example.PreferenceActivity2"/>
</PreferenceScreen>

我没有到主题应用到任何东西,但应用程序本身。

I didn't have to apply the theme to anything but the application itself.