设置偏好颜色Android

时间:2015-03-08 06:46:30

标签: android android-layout

SettingFragment.java

import android.os.Bundle;
import android.preference.PreferenceFragment;

public class SettingsFragment extends PreferenceFragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.prefs);

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // getView().setBackgroundColor(Color.WHITE);
        // getView().setClickable(true);
    }
}

style.xml

<resources>

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar"></style>

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:textAppearanceLarge">@style/MyTextAppearance</item>
</style>

<style name="PrefsTheme" parent="@android:style/Theme.Black.NoTitleBar">
    <item name="android:windowBackground">@android:color/black</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:listViewStyle">@style/listViewPrefs</item>
</style>

<style name="listViewPrefs" parent="@android:style/Widget.ListView">
    <item name="android:background">@android:color/black</item>
    <item name="android:cacheColorHint">@android:color/darker_gray</item>
</style>

清单

 <activity
            android:name="com.androidass.doubleclickflash.SettingsFragment"
            android:theme="@style/PrefsTheme"
            android:title="Settings" />

毕竟,我的设置仍然是白色透明的,但我可以通过在SettingFragment.java中取消注释getView().setBackgroundColor(Color.WHITE);来删除透明度,但我无法将SettingFragment的样式更改为黑暗。它完全没有android:theme="@style/PrefsTheme"。提前谢谢。

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,但发现我并不需要做所有的style.xml。删除样式主题和清单中的引用。直接进入SettingsFragment.java并用以下之一替换两个带注释的getView()语句:

`

    // set it as a drawable
    getView().setBackgroundResource(R.drawable.bg_drawable_resource);

    // or set it as a colour (one or the other, probably not worth doing both)
    getView().setBackgroundColor(Color.DKGRAY);

`