如何防止软键盘将自定义BottomAppBar向上推?

问题描述 投票:0回答:2

我尝试过各种插入填充、窗口插入、消耗插入(因为我什至不太了解窗口插入)...没有任何效果。我试图查找它,但每个人都有完全相反的问题 - 他们希望他们的底部应用程序栏被键盘向上推;我不,我希望它留在底部并将键盘绘制在它的顶部,我希望键盘遮盖底部应用程序栏。

我最近在主屏幕上添加了一个搜索栏(自定义文本字段,而不是撰写搜索小部件顶部栏),当我单击它时,底部应用程序栏会在键盘出现时向上推。

供参考,编译和目标SDK为34,最少26;截至今天,所有依赖项都是最新的(稳定版本)。边缘到边缘已NOT启用,我没有向任何类型的主要活动添加任何“安全绘图”或插入编码,也没有添加任何WindowCompat编码。

这是相关代码(减去我将其固定在屏幕底部的 500 次不同尝试):

MainActivity(设置内容块):

setContent {
    val application = (application as CellarApplication)
    CompositionLocalProvider(LocalCellarApplication provides application) {
        TobaccoCellarTheme(preferencesRepo = application.preferencesRepo) {
            Surface(
                modifier = Modifier
                    .fillMaxSize(),
                color = MaterialTheme.colorScheme.background,
            ) {
                CellarApp()
            }
        }  
    }
}
        

主屏支架:

Scaffold(
    modifier = modifier
        .nestedScroll(scrollBehavior.nestedScrollConnection),
    topBar = {
        CellarTopAppBar(
            title = stringResource(HomeDestination.titleRes),
            scrollBehavior = scrollBehavior,
            canNavigateBack = false,
            navigateToCsvImport = navigateToCsvImport,
            navigateToSettings = navigateToSettings,
            showMenu = true,
            exportCsvHandler = viewmodel,
        )
    },
    bottomBar = {
        CellarBottomAppBar(
            modifier = Modifier,
            navigateToStats = navigateToStats,
            navigateToAddEntry = navigateToAddEntry,
            currentDestination = HomeDestination,
            filterViewModel = filterViewModel,
        )
    },
    snackbarHost = {
        SnackbarHost(
            hostState = snackbarHostState,
            modifier = Modifier
                .padding(0.dp)
           snackbar = { Snackbar(it) }
        )
    },
) { innerPadding ->
    Column (
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Top,
        modifier = Modifier
            .fillMaxSize()
            .padding(top = 64.dp, bottom = 52.dp, start = 0.dp, end = 0.dp)
    ) {
    // rest of code calling screen content top level composables

自定义底部应用程序栏可组合项(在定义顶部应用程序栏和应用程序容器可组合项的不同文件中定义):

@Composable
fun CellarBottomAppBar(
    currentDestination: NavigationDestination?,
    modifier: Modifier = Modifier,
    navigateToHome: () -> Unit = {},
    navigateToStats: () -> Unit = {},
    navigateToAddEntry: () -> Unit = {},
    filterViewModel: FilterViewModel,
) {
    BottomAppBar(
        modifier = modifier
            .fillMaxWidth()
            .height(52.dp)
            .padding(0.dp),
        containerColor = primaryLight,
        contentColor = LocalCustomColors.current.navIcon,
        contentPadding = PaddingValues(0.dp),
    ) {
        Row(
            // rest of the bottom app bar code
android android-jetpack-compose ime android-bottomappbar
2个回答
1
投票

也许 android:windowSoftInputMode="adjustNothing" 可以解决您的问题。

在此处阅读有关它和其他选项的更多信息

https://developer.android.com/develop/ui/views/touch-and-input/keyboard-input/visibility#Respond


0
投票

检查您的

AndroidManifest.xml
,看看您的活动的
android:windowSoftInputMode
是否设置为
adjustResize
。例如:

<activity
    android:name=".YourActivity"
    android:windowSoftInputMode="adjustResize">
</activity>

将其更改为其他值,例如

adjustPan
adjustNothing
可能会解决您的问题

© www.soinside.com 2019 - 2025. All rights reserved.