Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

android - PreferenceActivity and theme not applying

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

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

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:

alt text

Any workarounds?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...