問題タブ [switchpreference]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - How to create an Androidx custom Preference that includes an EditTextPreference and a Switch?
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: