我有一个底部导航 View 和一个出现在底部导航顶部的文本编辑器工具栏。我希望当单击编辑文本并弹出键盘时,底部导航隐藏并且只有工具栏随键盘移动。
我尝试过android:windowSoftInputMode="adjustResize"
,但它允许底部导航和工具栏移动。我也尝试过使用 android:windowSoftInputMode="adjustPan"
,但是,工具栏和导航都停止出现在键盘顶部。
这是我的 Activity 布局文件:
<RelativeLayout
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">
<!-- top toolbar -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rellayout1">
<include layout="@layout/layout_top_tabs"/>
</RelativeLayout>
<!--middle section body -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rellayout2"
android:layout_marginBottom="50dp"
android:layout_below="@+id/rellayout1">
<include layout="@layout/layout_centre_viewpager"/>
<fragment
android:id="@+id/fragment"
android:name="com.Write.TitleFrag"
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_title" />
<fragment
android:id="@+id/fragment2"
android:name="com.Write.BodyFrag"
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="wrap_content"
android:layout_below="@+id/fragment"
tools:layout="@layout/fragment_body" />
</RelativeLayout>
<!-- bottom navigation -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/WriteBottomNav">
<include layout="@layout/layout_bottom_navigation_view"/>
</RelativeLayout>
</RelativeLayout>
fragment2 包含编辑器和工具栏。 这是fragment2布局文件:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"
android:scrollbars="vertical">
<com.github.irshulx.Editor
android:id="@+id/editor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingRight="20dp"
android:focusedByDefault="true"
android:paddingBottom="100dp"
app:placeholder="Start writing here..."
app:render_type="Editor">
</com.github.irshulx.Editor>
</ScrollView>
<HorizontalScrollView
android:id="@+id/toolsbottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e6e6e6"
android:layout_alignParentBottom="true"
android:layout_marginBottom="0dp"
android:scrollbars="none">
<include layout="@layout/write_toolbar_editor" />
</HorizontalScrollView>
</RelativeLayout>
最佳答案
由于没有可靠的方法来判断键盘何时显示/显示,因此没有可靠的方法来做到这一点。输入模式选项都不了解任何有关导航的信息,没有内置方法可以执行此操作。当软键盘出现时,无法收到通知。您最好的选择是不需要此功能。
关于java - 如何在键盘出现时隐藏或保持底部导航向下,同时让文本编辑器工具栏上下移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57315991/