Change Preference Screen background color
Asked Answered
M

4

9

I change color PreferenceScreen with this code.But how get Preference Screen in main Preference activity and change Preference Screen color ???

getListView().setBackgroundColor(Color.TRANSPARENT);
    getListView().setCacheColorHint(Color.TRANSPARENT);
    getListView().setBackgroundColor(Color.rgb(4, 26, 55));
Monetary answered 3/10, 2012 at 15:8 Comment(0)
P
16

You can override OnCreate Method:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        view.setBackgroundColor(getResources().getColor(<COLOR>));
        return view;
    }

Or you can enter the following in styles.xml

<style name="PreferenceTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
        <item name="android:background">@android:color/white</item>
    </style>
Pullen answered 25/3, 2016 at 4:9 Comment(0)
S
1

Use a Style for your activity.

Shag answered 3/10, 2012 at 15:13 Comment(7)
If i use Style.Components in ListView and screens don't work.Monetary
I set this style(android:theme) for PreferenceActivity.Monetary
<style name="Theme.White" parent="@android:style/Theme.Light.NoTitleBar"> <item name="android:windowBackground">@color/white_color</item> <item name="android:preferenceScreenStyle">@color/white_color</item> <item name="android:colorBackground">@color/white_color</item> </style> and all PreferenceScreen black on scrollingMonetary
Did you assigned the theme to the activity in your manifest? <activity android:name="MyActivity" android:theme="@style/mystyle"/>Shag
Yes, main preference activity set now white and work good, but preferenceScreens blink (black\white) on scroll =(Monetary
That is a Selector issue. Now you need to theme your selector for the screen. https://mcmap.net/q/125603/-android-selector-amp-text-colorShag
Help me please. I don't understand how fix it.Monetary
H
1

Just extend AppTheme and use colorBackground attribute

<style name="PreferenceTheme" parent="@style/AppTheme">
    <item name="android:colorBackground">@color/colorBackground</item>
</style>
Highstepper answered 16/1, 2019 at 12:36 Comment(0)
M
1

I am using the PreferenceFragmentCompat, the below solution worked for me.

SettingsScreen

import android.os.Bundle
import android.util.TypedValue
import android.view.View
import androidx.annotation.ColorInt
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.almarai.easypick.R


class SettingsScreen : PreferenceFragmentCompat(), 
Preference.OnPreferenceChangeListener {

    override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {

    //Providing the XML file for the view to be created
    setPreferencesFromResource(R.xml.app_settings_preferences, rootKey)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

    //Get the Theme specific color
    val typedValue = TypedValue()
    val theme = requireContext().theme

    /*R.attr.colorBackgroundScreenBody is my own attr from attrs.xml file, 
    you can directly use R.color.red - Or any color from your colors.xml 
    file if you do not have multi-theme app.*/
    theme.resolveAttribute(R.attr.colorBackgroundScreenBody, typedValue, true)
    @ColorInt val color = typedValue.data

    view.setBackgroundColor(color)

    super.onViewCreated(view, savedInstanceState)
    }
}
Myotonia answered 8/6, 2020 at 7:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.