安卓偏好设置屏幕布局

10

我在我的应用程序中有以下偏好设置屏幕

<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>
所有东西都能正常工作,但是我的应用程序有自定义背景、文本颜色/大小,但我无法弄清如何格式化PreferenceScreen。我猜你需要将其指向另一个xml?但我不知道需要什么代码以及要进行哪些更改。主要问题是背景颜色,文本看起来还可以,但是背景颜色与我的应用程序不符。所以我想设置一个自定义的背景颜色,比如现在设置为红色(#ff0000)。
谢谢任何能帮助我解决这个问题的人。
1个回答

14
你可以在你的manifest中应用一个theme,例如:
<activity android:name=".Settings"
     android:theme="@style/YourStyle"/>

在您的styles.xml文件中(如果您没有该文件,请在values文件夹中创建它),您可以修改任何需要的内容。

例如:

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

我希望这可以帮到你


1
没有想过使用主题,但是非常完美地解决了问题,谢谢! - GFlam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接