Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set scroll position for long PreferenceScreen

Tags:

android

Android app has some very long preference screens, which always open at the top of the preference menu. I have some idea where the user wants to be in the preference menu. How can I force the preference screen to open scrolled to a specific preference item?

like image 743
kencorbin Avatar asked Mar 02 '26 03:03

kencorbin


1 Answers

You can just use scrollToPreference :

https://developer.android.com/reference/androidx/preference/PreferenceFragmentCompat#scrollToPreference(androidx.preference.Preference)

Example:

scrollToPreference(preferenceKey)

or:

scrollToPreference(preference)
like image 65
android developer Avatar answered Mar 04 '26 18:03

android developer