Android 软键盘上推隐藏操作栏或叠加编辑文本
我有一个简单的布局问题。 如果我设定Android 软键盘上推隐藏操作栏或叠加编辑文本,android,android-layout,android-softkeyboard,soft-keyboard,Android,Android Layout,Android Softkeyboard,Soft Keyboard,我有一个简单的布局问题。 如果我设定 android:windowSoftInputMode="stateHidden|adjustResize" 发生这种情况: 在任何情况下,只有当我从横向打开键盘,然后旋转(键盘打开)时,才会发生这种情况。 在正常使用中(旋转然后打开键盘),这不会发生 如果我设定 android:windowSoftInputMode="stateHidden|adjustResize" android:windowSoftInputMode="stateHidden
android:windowSoftInputMode="stateHidden|adjustResize"
发生这种情况:
在任何情况下,只有当我从横向打开键盘,然后旋转(键盘打开)时,才会发生这种情况。
在正常使用中(旋转然后打开键盘),这不会发生
如果我设定
android:windowSoftInputMode="stateHidden|adjustResize"
android:windowSoftInputMode="stateHidden|adjustPan"
ActionBar被推上
此处为布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/a"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_below="@+id/ad_view_chat"
android:layout_gravity="bottom"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listChatLayout"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_above="@+id/switchbuttons"
android:layout_marginTop="2dp">
<ListView
android:id="@+id/listChat"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:longClickable="true"
android:stackFromBottom="true"
android:transcriptMode="normal" />
</LinearLayout>
<RelativeLayout
android:id="@+id/switchbuttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_above="@+id/messaggiLayout"
android:layout_centerHorizontal="true">
<RadioButton
android:id="@+id/cmd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:checked="false"
android:gravity="center"
android:text="Cmd"
android:layout_marginLeft="5dp" />
<RadioButton
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_toRightOf="@+id/cmd"
android:checked="true"
android:gravity="center"
android:text="Message" />
<com.rey.material.widget.Button
android:id="@+id/button_arrow_down"
android:background = "@drawable/arrow_down"
style="@style/FlatColorButtonRippleStyle"
android:layout_width="40dp"
android:layout_height="40dp"
android:text=""
android:textAppearance="@style/Base.TextAppearance.AppCompat.Button"
android:textColor="#FF2196F3"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button_arrow_up"
android:layout_toEndOf="@+id/button_arrow_up"
android:layout_marginLeft="3dp" />
<com.rey.material.widget.Button
android:id="@+id/button_arrow_up"
style="@style/FlatColorButtonRippleStyle"
android:layout_width="40dp"
android:layout_height="40dp"
android:background = "@drawable/arrow_up"
android:text=""
android:textAppearance="@style/Base.TextAppearance.AppCompat.Button"
android:textColor="#FF2196F3"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/message"
android:layout_toEndOf="@+id/message"
android:layout_marginLeft="20dp" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/listChatLayout"
android:layout_alignParentBottom="true"
android:id="@+id/messaggiLayout">
<EditText
android:id="@+id/messaggi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:imeOptions="actionSend|flagNoFullscreen"
android:inputType="textImeMultiLine"
android:layout_toLeftOf="@+id/button_send"
android:maxLength="100">
<requestFocus />
</EditText>
<com.rey.material.widget.Button
android:id="@+id/button_send"
style="@style/FlatColorButtonRippleStyle"
android:layout_width="50dp"
android:layout_alignParentRight="true"
android:background = "@drawable/send2"
android:layout_height="50dp"
android:text=""
android:textAppearance="@style/Base.TextAppearance.AppCompat.Button"
android:textColor="#FF2196F3" />
</RelativeLayout>
</RelativeLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/ad_view_chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_chat_ad_unit_id" />
</RelativeLayout>
修复:
问题出在mikepenz MaterialDrawer身上。
现在我联系了mike,我们修复了这个错误当系统(u UI)标志(u LAYOUT)全屏标志时出现的问题标志需要在
状态栏
后面显示抽屉
作为解决方案,我实现了KeyboardUtil
,它将键盘的高度作为填充添加到contentview中。由于显示键盘时没有侦听器获取事件,因此这是通过OnGlobalLayoutListener
完成的
@MarcoCount有一个特殊的用例,导致KeyboardUtil
无法正常工作。在他的帮助下,我们得到了一个更新版本的KeyboardUtil
,它现在在屏幕旋转时也能工作,键盘一直显示整个时间
以下是更新的键盘util
的来源,以防有人需要它。它也可以在GitHub上的
尝试在布局中使用滚动视图,而不是在清单文件中添加adjustpan。 使用滚动视图,您的屏幕可以调整和滚动,这不会向上滚动工具栏或操作栏,也不会隐藏您的布局
<ScrollView>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars = "vertical"
android:scrollbarStyle="insideInset"
> </ScrollView>
android:layout\u width=“匹配父项”
android:layout\u height=“match\u parent”
android:fillViewport=“true”
android:scrollbars=“垂直”
android:scrollbarStyle=“insideInset”
>
尝试将此布局用作父布局。但是滚动视图不能用作基本布局,因为您必须在线性或相对布局内使用滚动视图