简体   繁体   中英

Android Jetpack Compose BasicTextField scroll to top when get focus, how to stop it

When BasicTextField has too much content to scroll up and down, scroll to bottom, request focus and show keyborad, it will scroll to top automatically. I want it stay in its original postion, how can I do?

You can simply handle it like this and modify the code according to your needs

val scrollState = rememberScrollState()
var verticalScrollEnabled by remember { mutableStateOf(false)}
BasicTextField(
    modifier = Modifier
        .onFocusChanged {
             if (it.isFocused) {
                 verticalScrollEnabled = true
             }
         }
        .verticalScroll(scrollState, verticalScrollEnabled),
             value = "LONG TEXT",
             onValueChange = {}
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM