在whatsApp或google messenger中,状态栏不会在显示的键盘上向上滑动,ListView
会根据Edittext
调整大小。根据stackoverflow中的一些研究,我在AdjustResize
中设置了android:windowSoftInputMode
属性。该属性会调整ListView
的大小,但也可以向上滑动状态栏。我想要持久状态栏。我也试过android:fitsSystemWindows="true"
但没有用。我使用支持Toolbar
代替ActionBar
和AppCompactActivity
Theme.AppCompact.Light.NoActionBar
主题。
的manifest.xml
<activity
android:name=".activities.ConversationActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />
style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
chat.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/re/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_conversation"
tools:context=".activities.ConversationActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/tb_conversation"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/white"
android:fitsSystemWindows="true"
android:gravity="center_horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title_conversation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/img_doctor"
android:layout_toStartOf="@+id/img_doctor"
android:gravity="center"
android:text="text"
android:textSize="20sp"
android:textStyle="normal" />
<com.views.CircularNetworkImageView
android:id="@+id/img_doctor"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:padding="10dp"
android:src="@drawable/ic_tab_profile" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/tb_conversation"
android:layout_centerHorizontal="true"
android:background="@color/colorAppGray" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/view">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/view2"
android:divider="@null"
android:dividerHeight="0dp" />
<View
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="@+id/input_layout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@color/colorAppGray" />
<RelativeLayout
android:id="@+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:gravity="bottom"
android:layout_alignParentStart="true"
android:background="@android:color/white">
<EditText
android:id="@+id/et_msgInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_toLeftOf="@+id/btn_send_image"
android:layout_toStartOf="@+id/btn_send_image"
android:background="@drawable/res_bg_conversation_et"
android:gravity="center_vertical"
android:maxLines="5"
android:nextFocusLeft="@+id/btn_send_image"
android:nextFocusUp="@+id/btn_send_image"
android:paddingLeft="18dp"
android:paddingTop="18dp"
android:paddingBottom="18dp"
android:paddingRight="10dp"
android:scrollbars="vertical"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="@android:color/black" />
<ImageButton
android:id="@+id/btn_send_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@android:color/transparent"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="20dp"
android:src="@drawable/ic_camera"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/txt_send_msg"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignBottom="@+id/et_msgInput"
android:layout_toRightOf="@+id/et_msgInput"
android:gravity="center"
android:text="Gonder"
android:visibility="invisible" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
code.java
Toolbar toolbar = (Toolbar) findViewById(R.id.tb_conversation);
setSupportActionBar(toolbar);
图片
首先看
点击Edittext
键盘后显示
预期(状态栏保留在其中)
发生(状态栏滑出视图):(
答案 0 :(得分:2)
使用我的以下代码更改manifest.xml
<activity
android:name=".activities.ConversationActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
您也可以在java文件中动态更改
@Override
public void onResume() {
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
super.onResume();
}
@Override
public void onPause() {
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
super.onPause();
}
我还建议使用如下图像的片段。
答案 1 :(得分:2)
尝试不添加windowSoftinput模式
<activity
android:name="com.app.name"
android:screenOrientation="portrait"
/>
为我工作
答案 2 :(得分:1)
我找到了解决问题的方法。问题不在于AdjustResize
或AdjustPan
。这是Activity
全屏。在全屏Activity
中,键盘的调整机制无法正常工作。
答案 3 :(得分:0)
尝试添加此
<activity
android:name="com.app.name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustPan"/>
答案 4 :(得分:0)
您可以尝试Chitrang的解决方案。
他已经放了所有代码,但它似乎对他有用,只需删除<com.views.CircularNetworkImageView
,因为该类不存在。