Questions tagged [android-preferences]
The android-preferences tag has no usage guidance.
1,916
questions
0
votes
1
answer
13
views
SwitchPreferenceCompat wrong "off" color on real device
I'm using SwitchPreferenceCompat from androidx.preference:preference:1.2.0. In Android Studio preview everything looks good:
But in real device it look this:
Here my preferences.xml:
<...
-1
votes
1
answer
24
views
Keep checkbox state after shutting down app
i have app with multiple checkboxes, which gets disabled after checking all three of them. The problem is, when i close the app, the state doesnt presist. My code:
private fun ...
0
votes
0
answers
11
views
Is it possible to import a file from Preference Fragment?
I created a Preference Fragment for Settings in Android Studio and I want to have a Import Button, when I click it, to open Folder and Pick a File...
Then, the picked file will be copied and saved ...
0
votes
1
answer
11
views
Why, in androidx settings/preferences, am I getting "java.lang.String cannot be cast to java.lang.Integer" exception?
In my preferences.xml I have this:
<ListPreference
app:dependency="@string/auto_record_key"
app:defaultValue="3"
app:dialogTitle="@...
1
vote
1
answer
45
views
Implementation of getString() of PreferenceDataStore method
I am using a custom DataStore which inherits PreferenceDataStore to store preferences for settings activity in my android application. I want to implement the getString() method as the ...
0
votes
0
answers
30
views
Retrieve data from the observer, to read from jetpack Datastore
I am trying to read a string saved with preference Datastore. Data within the brackets (parametros.texto) is correct and properly shown in textviewTextoA, but shows empty in textviewTextoB outside ...
0
votes
1
answer
36
views
MultiSelectListPreference keeps old values. Is it a bug and what can be done?
If the array of choices for MultiSelectListPreference is changed, the previous stored selections in preferences can't be removed by the user.
I wrote a MultiSelectListPreference in xml as follows and ...
1
vote
1
answer
150
views
Where is Preferences DataStore (Jetpack) stored?
SharedPreferences (though has many downsides) has the upside of accessing the XML where the data is stored.
Where does Jetpack DataStore store the data and is the file accessible?
0
votes
1
answer
26
views
kotlin, why coroutines launch block only runs one function in it when a DataStore is used in the function,
Having a coroutines launch to execute three functions.
scope.launch {
getPrefsOne()
getPrefsTwo()
getPrefsThree()
}
If the function is doing ...
2
votes
1
answer
282
views
How to use material 3 Switch in PreferenceFragmentCompat programmatically?
SwitchPreferenceCompat still retains the old Switch style, I know to be able to style it Material 3 in the following way:
theme.xml
<style name="Theme.Material3.Preference" parent="...
0
votes
1
answer
41
views
How to upgrade to AndroidX preferences?
I'm trying to upgrade to the new Androidx preference library. All tutorials I find involve creating masses of intertwined XML files, activities, and fragments, which makes everything much more ...
0
votes
1
answer
27
views
Problems Creating User Preferences File
I'm currently creating an android app, in which you can train maths. Today i wanted to add a Settings page so i followed the guide from the official android docs: https://developer.android.com/develop/...
0
votes
0
answers
42
views
Migrating from android.preference.DialogPreference to androidx.preference.DialogPreference is causing issues
This is the TimePreference class which extends DialogPreference
import android.content.Context;
import android.content.res.TypedArray;
import androidx.preference.DialogPreference;
import android.util....
0
votes
1
answer
36
views
Change SwitchPreference position in a PreferenceScreen layout
I need to implement a SettingsFragment for an Android Auto App; From my research, I need to use a PreferenceScreen layout;
Is there a way to change the switch button position from right (implicit) to ...
0
votes
0
answers
117
views
Can we use DataStore<T> in PreferenceScreen?
Same as title, I want to use DataStore for storing a custom type ServerPreferences but I don't want to use PreferenceDataStore separately for it.
Is there any way I can use DataStore<T> with ...
0
votes
0
answers
26
views
Can't open an Activity from PreferenceFragmentCompat
I have a settings item, which should open an Activity. But my app is craches with Unable to find explicit activity class, when I tap the settings item. Any suggestions? Thank you.
Manifest:
<...
0
votes
1
answer
26
views
Problems with create custom PreferenceScreen and mange each one in SettingsFragment - kotlin
According to this question I am trying to create a custom layout and add it to my root PreferenceScreen XML, but I am facing some problems, first, the switch_preference_layout.xml looks corrupted when ...
7
votes
2
answers
882
views
New Android 12+ MaterialSwitch and androidx.preference
So i'm updating my apps to fully support Monet and Material You guidelines, and the official site mentions a new design for the switches. I used it, and that's the result:
I have a preference screen ...
0
votes
1
answer
62
views
Hide a Preference-item depending on the state (enabled/disabled) of another Preference in PreferenceScreen
I'm creating a settings screen, and I have a few settings items:
SwitchPreferenceCompat and my CustomPreference.
I need the СustomPreference to disappear(hide) when the SwitchPreferenceCompat is ...
0
votes
1
answer
35
views
PreferenceManager(context) is private in the pacakage
PreferenceManager(context) is private in the package and I need to convert it to public to use. I don't know how to do so. So, can anyone help me ?
0
votes
1
answer
150
views
'PreferenceManager()' is not public in 'android.preference.PreferenceManager'
This line gives me error :-
preferenceManagers = new PreferenceManager(getApplicationContext());
This error I get :-
'PreferenceManager()' is not public in 'android.preference.PreferenceManager'. ...
0
votes
1
answer
25
views
how to display preference values
I'm trying to migrate the preferences part of my app because of warning
default constructor in android.preference.preferenceactivity is deprecated
But, even after reading a lot of ressources, I don't ...
0
votes
0
answers
40
views
How to find out the Activity Intent name from which the user back-pressed (!) to the current Activity?
I have SettingsActivity + SettingsFragment + my CustomPreference with built into XML Intent for opening settings of Notification Channel:
preferences.xml:
<my.package.CustomPreference
...
1
vote
0
answers
84
views
Android - DropDownPreference not working in Landscape orientation
I have a pretty weird issue. In my SettingsActivity, I have a DropDownPreference (the one that displays a list when clicked), and it works fine on Portrait mode.
However, when I go into Landscape mode,...
2
votes
1
answer
85
views
Implement a split preference in Android
I feel like there must be a straight-forward way to achieve this, but I haven't found it so far.
Essentially, in the stock settings app, there are a handful of preferences that are "split" - ...
0
votes
0
answers
76
views
inflating class (not found)android.support.v7.preference.PreferenceScreen
hi i have an issue with my app trying to add dark mod light mod option but keep getting this error
android.view.InflateException: Binary XML file line #1: Error inflating class (not found)android....
0
votes
0
answers
32
views
Hiding a TextView contained in a subclass of Preference
As of now: When the user enters the settings page there's a single option that is prefixed with "New". When the user clicks this option nothing happens.
Objective: When the user enters the ...
0
votes
1
answer
124
views
Referencing an Android Preference Tag's layout
I've been trying to reference a TextView inside an XML file that's used inside a Preference tag. Below is a simplified version of my file structure:
primary.xml
<PreferenceScreen
.
.
.
<...
0
votes
0
answers
73
views
How to make Preference widget appear below title in Android?
I'm new to Android development and wonder if there is an easy way to have a Preference (androidx.preference.Preference) with the widget appearing below the title? I am aware that layoutResource can be ...
1
vote
0
answers
174
views
Whenever i try to implement Dark mode in my Settings, i get this crash (Android Studio, java)
I get the linear layout error only when i try to implement dark mode from PreferenceSwitchCompat
Java:
enter code here public static class SettingsFragment extends PreferenceFragmentCompat {
...
2
votes
1
answer
814
views
How to get all keys of Android Preferences DataStore
As mentioned by the title, is there any way to obtain all the keys stored in an Android Jetpack Preferences DataStore, e.g., dataStore
val Context.dataStore: DataStore<Preferences> by ...
1
vote
2
answers
2k
views
Android Preferences DataStore Flow Doesn't Emit Same Value
Just testing Preferences DataStore and found out that the provided Flow output won't emit same value, my setup as followed:
DataStore Util Class:
object DataStore {
private val Context.settings by ...
0
votes
1
answer
234
views
MapFragment becomes slow after navigating back to it from a preferencesFragment
I added a Preferences Fragment to an application. I am using an ActionBar drop-down menu to navigate to the Preferences Fragment and also using the ActionBar's OnUpNavigation button to return to the ...
1
vote
1
answer
61
views
Preference Screen adding a entity header
How can I add such called "Entity Header" in a PreferenceScreen like listed in the docs here:
https://source.android.com/devices/tech/settings/settings-guidelines#entity_header
https://...
1
vote
1
answer
156
views
androidx.preference.SwitchPreferenceCompat cannot be cast to androidx.preference.PreferenceGroup
So I'm trying to make an options menu in my android app but when I click on it in the emulator the app crashes and I get the following error:
androidx.preference.SwitchPreferenceCompat cannot be cast ...
0
votes
1
answer
109
views
Android change Dialog background color from app settings via styles
I want to change default Dialog background color of my PreferenceActivity (Dialog that opens where we choose option from list in settings). Now the background of Dialog is always white although I ...
0
votes
2
answers
56
views
Not able to find "extra" attribute in jetpack preference in Android
Am trying to build Settings kind of App, I choose to use Preferences to build UI .
I am using jet pack preferences (androidx.preference.Preference) ,
If I want to launch fragment with some extras ,can ...
1
vote
0
answers
109
views
How do I open the app settings screen with notification settings via preferences.xml
How do I open the app settings screen with notification settings via preferences.xml
But my way doesn't work. And the question is how to add it to AndroidManifest. Please tell us everything in detail ...
3
votes
2
answers
78
views
How to create a dual action (normal + switch) preference in Android?
Is there any way to achieve this dual-action preference item? Preferably via a third party library but via a simple implementation if necessary.
The 'wireless debugging' preference in Android's ...
0
votes
1
answer
116
views
can I add custom attributes to components in preferences.xml without making custom views?
I am trying to store a state or data with some sort of custom attribute to existing components in the preferences.xml that I can later reference and read in code. I want to avoid creating custom views ...
1
vote
0
answers
78
views
How to set an Android-X custom preference height?
I am trying to create a custom preference used in a fragment. That preference will have an icon, a long text and a hyperlink to link somewhere.
For that I create a class that extends androidx....
8
votes
3
answers
1k
views
Adjust androidx.preference dialogs to follow Material You
I have two apps containing a preference section, and i'm using the preference library, the latest version available at the time of writing:
implementation "androidx.preference:preference:1.2....
1
vote
1
answer
130
views
How to add On-screen button to PreferenceScreen
I' m using AndroidX Preference library version 1.1.1. It provides components like SwitchPreferenceCompat and MultiSelectListPreference.
And in Android Settings Design Guidelines, there are samples of ...
1
vote
2
answers
53
views
Android Preferences defaultValue not works
Here is my preferences.xml
<PreferenceCategory android:title="@string/pref_cat_recognition">
<ListPreference
android:entries="@array/unitsArray"
...
0
votes
0
answers
143
views
How can i save the selected value from ListPreference so it doesn't reset to the defaultValue when I restart the app in Android Studio (Java)?
I'm trying to make a ListPreference to change the design of my app.
This also works but unfortunately the setting is reset to the defaultValue when the app is restarted. Somehow I have to save this ...
0
votes
1
answer
124
views
SwitchPreferenceCompat setOnPreferenceChangeListener crashes app
My application crash when I go to my settings activity and the error is
java.lang.NullPointerException: Attempt to invoke virtual method 'void
androidx.preference.SwitchPreferenceCompat....
1
vote
1
answer
199
views
Customize XML for setting Fragment Kotlin
I need to customize my layout which is root_preferences.
for instance: set gravity for SwitchPreferenceCompat or EditTextPreference.
It is the first time that I use setting fragment and I think both ...
-2
votes
2
answers
370
views
uses permission Shared preferences
devs, in my android application I'm using shared preferences,
my question is: do I need to add any special user permission in the file AndroidManifest.xml?
4
votes
0
answers
306
views
setTargetFragment is depricated PreferenceDialogFragmentCompat
I am trying to open a PreferenceDialogFragmentCompat from my PreferenceFragmentCompat by doing this:
@Override
public void onDisplayPreferenceDialog(Preference preference) {
// check if dialog is ...
0
votes
1
answer
419
views
Replace deprecated setTargetFragment() in PreferencesFragment
I cannot figure out how to replace setTargetFragment() in the code sample below, which is from my Preferencesfragment obviously:
override fun onPreferenceStartFragment(
caller: ...