Black screen in inner preferenceScreen

前端 未结 4 1982
执笔经年
执笔经年 2021-01-02 04:56

My PreferenceActivity contains a nested PreferenceScreen in another PreferenceScreen and I\'m applying a theme to my PrefenceAct

相关标签:
4条回答
  • 2021-01-02 05:23

    What worked for me: Simply set a list style:

    <style name="Theme.Preferences" parent="android:Theme.Light" >
        <item name="android:listViewStyle">@style/lightListView</item>
    </style>
    <style name="lightListView">
        <item name="android:background">#ffffff<item>
    </style>
    
    0 讨论(0)
  • 2021-01-02 05:23

    Macarse's answer is perfect, I was searching for classic white background so I changed this line in his answer:

    a.getDialog().getWindow().setBackgroundDrawableResource(R.drawable.background);
    

    to:

    a.getDialog().getWindow().setBackgroundDrawableResource(android.R.color.white);
    

    and it works nicely.

    0 讨论(0)
  • 2021-01-02 05:27

    Workaround:

    1) Prepare 2 PreferenceScreen xml's instead of sub PreferenceScreen using;

    2) Add secondary PreferenceScreen Activity to AndroidManifest.xml:

    <activity android:name="com.example.PreferenceActivity2"
              android:label="Issue4611"
              android:theme="@android:style/Theme.Light">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>
    

    3) For show secondary PreferenceScreen use in your first PreferenceScreen:

    <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>
    

    Example

    0 讨论(0)
  • 2021-01-02 05:29

    I found a way to do it but it quite a hack.

    This is my prefs.xml

    <PreferenceCategory
        android:title="@string/hello">
    
        <CheckBoxPreference
            key="pref_update_key"
            android:title="@string/hello"
            android:summaryOn="@string/hello"
            android:summaryOff="@string/hello"
            android:persistent="true"
            android:defaultValue="false" />
    
    </PreferenceCategory>
    
    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="pref_second_preferencescreen_key" android:title="@string/hello">
            <CheckBoxPreference
            key="pref_update_key"
            android:title="@string/hello"
            android:summaryOn="@string/hello"
            android:summaryOff="@string/hello"
            android:persistent="true"
            android:defaultValue="false" />
    </PreferenceScreen>
    

    And this is my code for the class that extends PreferenceActivity

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.layout.prefs);
        getWindow().setBackgroundDrawableResource(R.drawable.background);
    
        PreferenceScreen b = (PreferenceScreen) findPreference("pref_second_preferencescreen_key");
        b.setOnPreferenceClickListener(new OnPreferenceClickListener() {
    
            @Override
            public boolean onPreferenceClick(Preference preference) {
                PreferenceScreen a = (PreferenceScreen) preference;
                a.getDialog().getWindow().setBackgroundDrawableResource(R.drawable.background);
                return false;
            }
        });
    }
    
    0 讨论(0)
提交回复
热议问题