gpt4 book ai didi

android - 我可以同时拥有 "adjustResize"软键盘行为和状态栏后面的工具栏吗?

转载 作者:可可西里 更新时间:2023-11-01 19:06:53 26 4
gpt4 key购买 nike

在我的 Android 应用程序中,对软键盘使用 adjustResize 行为对我来说至关重要。因此,用户可以向下滚动到其他 UI 元素,例如“继续”按钮。

我注意到 adjustResize 仅在布局根元素中同时具有 Manifest 设置和 android:fitsSystemWindows="true" 时才有效。 (如有错误请指正!)

但是对于 android:fitsSystemWindows="true",工具栏不再位于状态栏后面。这很有道理,但不是我想要的。

当工具栏位于其后面时,状态栏具有与我的工具栏颜色匹配的深色阴影。 android:fitsSystemWindows="true" 是一个无色状态栏和一个比我想要的低 24dp 的工具栏。

为了 adjustResize 键盘行为,我将放弃匹配的彩色状态栏。但我的问题是,是否可以同时拥有两者? 我敢梦想既美观又方便吗?

更有经验的人知道设置的神奇组合吗?或者,作为一种解决方法,可以明确地为状态栏着色?

仅供引用:

这些是具有 RelativeLayout 根元素的 Activity,其中一些有 ListViewEditText

工具栏是 android.support.v7.widget.Toolbar

可能相关的样式项:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowContentOverlay">@null</item>

PS - 我已经阅读了数十个关于软键盘行为的类似问题,但无法找到任何有助于解决工具栏意外影响的问题。反之亦然,很多关于工具栏/状态栏行为的样式问题,但似乎没有什么相关的。尽管如此,如果我遗漏了什么,抱歉!

非常感谢!

编辑

我一直在尝试删除 android:fitsSystemWindows="true" 并添加更多 ScrollView 或尝试将所有内容放入同一个 ScrollView。这没有任何作用。

如果我删除 android:fitsSystemWindows="true" 那么 UI 的底部会“粘”到屏幕底部——它不会“调整大小”而是粘到顶部软键盘的功能,就像我希望它与 Manifest 中设置的 adjustResize 一样。

在 Root View 中设置 android:fitsSystemWindows="true" 可以让 UI 像我期望的那样调整大小——但它也使得工具栏不再绘制在 statusBar 后面。

所以我仍然是我开始的地方:(

添加布局 XML 代码示例:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- CoordinatorLayout because this view uses SnackBars -->

<!-- Relative Layout to lock "continue" button bar to bottom -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Main content, that scrolls with or without keyboard -->
<!-- Correctly sits behind transparent Status Bar -->
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/footer_persistent_height">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- ACTUAL VIEWS DELETED FOR BREVITY / CLARITY -->
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>


<!-- Bottom nav bar -->
<!-- Correctly sits at bottom of UI when keyboard is not visible -->
<!-- PROBLEM: Not accessible when soft keyboard is visible -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="?android:attr/buttonBarStyle">

<Button
android:id="@+id/skip_button"
android:theme="@style/ButtonContinueGrey"
android:onClick="skipClickHandler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".5"
style="?android:attr/buttonBarButtonStyle"/>

<Button
android:id="@+id/button_progress"
android:theme="@style/ButtonContinueColored"
android:onClick="continueClickHandler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".5"
style="?android:attr/buttonBarButtonStyle"/>
</LinearLayout>

</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

最佳答案

我找到了一个似乎适用于操作系统的解决方案。首先将 fitSystemWindows = true 设置为您希望对窗口使用react的 View ,然后告诉它忽略顶部填充:

  ViewCompat.setOnApplyWindowInsetsListener(yourView, (view, insets) ->
ViewCompat.onApplyWindowInsets(yourView,
insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), 0,
insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()))
);

在这里阅读更多:https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec

关于android - 我可以同时拥有 "adjustResize"软键盘行为和状态栏后面的工具栏吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42442812/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com