I would like to have an androidx EditText + Switch preference like the following image:
The preference should give to the user the possibility to set the value of the Manual Correction by clicking on the text (like a normal EditTextPreference), and to activate/deactivate the Manual Correction using the Switch.
(As a note, I'll add a vertical separator between Text and Switch, like the Wi-Fi preference of Android System Settings).
All the Java examples I found are related to the old Android Preference, but I use the new androidx.preference.PreferenceScreen
.
I load the preference screen into a PreferenceFragmentCompat
using addPreferencesFromResource(R.xml.app_preferences)
, following the standard Android guidelines.
To be complete, if I would add them as separated preferences, I should use the following app_preferences.xml
code:
<androidx.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
...
<androidx.preference.SwitchPreferenceCompat
android:key="prefManualCorrectionIsActive"
... />
<androidx.preference.EditTextPreference
android:key="prefManualCorrectionValue"
... />
...
</androidx.preference.PreferenceScreen>