General settings

I want to show the editing window in the general settings, which should be read only for the user, but I should be able to change it using the code. how to achieve this?

+3
source share
6 answers

This tutorial is good for setting up. In addition, if you want to change the settings outside PreferenceActivity, you must use the editor For example:

Editor e = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).edit();
e.putString("yourPreference", "default value");
e.commit();

I hope this helps

In addition, as shown in the documentation here , it is PreferenceActivityused to display a visual style of settings. In addition, as indicated in the same link, "settings are automatically saved until SharedPreferenceswhen the user interacts with them."

, , , , TextView EditText PreferenceActivity, PreferenceActivity. , .

+3

, , TextView. EditText - TextView, . , TextView, ,

TextView tv = new TextView(this);
tv.setText("");
+2

PreferenceActivity? , XML android:enabled="false" , .

+2

, u pref android:editable="false" . .

0
source

One way to display non-editable text is to use the standard Preference parameter and its summary (small text appears under the Preference heading).

<Preference
    android:key="text_preference"
    android:selectable="false"
    android:title="Title" />

.

    Preference textPreference = (Preference) getPreferenceManager().findPreference("text_preference");
    textPreference.setSummary("Text");
0
source

Try this in XML: android: selectable = "false"

-1
source

Source: https://habr.com/ru/post/1794457/


All Articles