【发布时间】:2016-05-31 06:59:52
【问题描述】:
在whatsApp 或google messenger 中,状态栏不会在显示的键盘上向上滑动,ListView根据Edittext 调整大小。根据stackoverflow中的一些研究,我在android:windowSoftInputMode中设置了AdjustResize属性。该属性会调整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后显示键盘
预期(状态栏保留在原位)
正在发生(状态栏滑出视图):(
【问题讨论】:
-
@J.Chomel 代码已添加.. 请查看
-
现在我们有一些东西可以咀嚼了,谢谢 Bilal!
-
也感谢你给我这个宝贵的建议。现在我的问题更多的是解决方案。 :)
-
您的问题与stackoverflow.com/questions/32283546/… 非常相似。你试过它的解决方案吗?
-
你能发布一些关于你的行为的图片或演示视频吗?因为我试过你的代码,状态栏没有问题。