Android Preference Screen Layout

眉间皱痕 提交于 2019-12-20 19:47:26

问题


I have the following preference screen in my app

<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="edittexvalue"
android:id="@+id/edittextvalue"
android:title="Title Here"
android:summary="Summary Here" 
android:defaultValue="Some Value"/>
<Preference
android:key="customPref"
android:title="Title Here"
android:summary="Summary Here"/>
</PreferenceScreen>

All of that works just fine however my app i have custom backgrounds and text colors/sizes but i can't figure out how to format the PreferenceScreen I assume you point this at another xml? but can't figure out the code i need and what changes should be made. The main concern is the background color the text is fine i guess but the background just doesn't match the rest of my app. So i'd like to set a custom background color lets say red for now (#ff0000)

I thank anyone that can help me with this problem


回答1:


You can to apply a theme to it in your manifest, for example

<activity android:name=".Settings"
     android:theme="@style/YourStyle"/>

and in your styles.xml (if you dont have one, create it in the values folder) you can modify whatever you need

For example

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourStyle" parent="android:Theme.Light">
    <item name="android:listViewStyle">@style/Widget.ListView</item>
    <item name="android:windowNoTitle">true</item>
</style>

<style name="Widget" parent="android:Widget">
</style>

<style name="Widget.ListView">
    <item name="android:background">@color/white</item>
    <item name="android:divider">@color/gray_division</item>
    <item name="android:dividerHeight">2dip</item>       
</style>
</resources>

I hope this helps



来源:https://stackoverflow.com/questions/5572149/android-preference-screen-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!