change background color of Preference

后端 未结 8 1778
北荒
北荒 2020-12-02 10:25

I have a PreferenceCategory, xml file and I have defined all preferences in it, I call this from class that extends PreferenceActivity. I am unable

相关标签:
8条回答
  • 2020-12-02 11:09

    android:background is not an available attribute, according to the documentation.

    It is possible you could theme the PreferenceActivity to achieve your color change, though I have not tried this, because I want my preferences to look like those of the rest of Android, to improve usability of the app.

    0 讨论(0)
  • 2020-12-02 11:11

    You can define a theme and then set this for your PreferenceActivity in the manifest. Your theme can then define a a background color or a windowBackground image should you prefer that.

    Manifest:

        <activity android:label="@string/app_label" android:name=".client.PreferencesActivity"
            android:theme="@style/PreferencesTheme">
            <intent-filter>                                
            </intent-filter>
        </activity>
    

    Then add the theme to your styles.xml

    <style name="PreferencesTheme">
        <item name="android:windowBackground">@drawable/background_image</item>
        <item name="android:background">#FFEAEAEA</item>
    </style>
    

    In the above snippet there's both a background color and a background image defined to show how to do it.

    0 讨论(0)
提交回复
热议问题