Android 全屏,底部有工具栏和编辑文本
我正在使用聊天应用程序Android。 我正在创建聊天屏幕,就像Whats应用程序一样Android 全屏,底部有工具栏和编辑文本,android,android-edittext,android-toolbar,Android,Android Edittext,Android Toolbar,我正在使用聊天应用程序Android。 我正在创建聊天屏幕,就像Whats应用程序一样 EditText位于底部,而工具栏位于顶部 我正在使用以下代码 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_h
EditText
位于底部,而工具栏
位于顶部
我正在使用以下代码
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:id="@+id/llFrame">
<include layout="@layout/actionbar_chat"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/White"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:layout_marginTop="?android:attr/actionBarSize"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewChat"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.8"
android:divider="@null"
android:dividerHeight="0dp"
android:paddingBottom="10dp"
android:text="@string/hello_world"
android:layout_marginTop="@dimen/_5sdp"/>
<LinearLayout
android:id="@+id/form"
android:layout_width="match_parent"
android:layout_height="@dimen/_35sdp"
android:background="#91f1f1f1"
android:orientation="horizontal"
android:paddingBottom="2dp"
android:gravity="center">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingRight="@dimen/_2sdp"
android:paddingLeft="@dimen/_10sdp"
android:paddingTop="@dimen/_2sdp"
android:paddingBottom="@dimen/_2sdp"
>
<com.cloudzon.gratzeez1.property.CustomEditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
android:background="@drawable/rectangle_"
android:padding="@dimen/_2sdp"
/>
</LinearLayout>
<com.cloudzon.gratzeez1.property.CustomTextView
android:id="@+id/tvSendMessage"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:layout_margin="@dimen/_2sdp"
android:text="Send"
android:textSize="@dimen/_15sdp"
android:layout_gravity="center"
android:gravity="center"
/>
</LinearLayout>
现在,当我单击底部的EditText
时,软键盘打开,但将上面的布局推到顶部,我无法看到工具栏
相反,工具栏
应该在用户打开edittext后固定在其位置
谢谢试着换衣服
android:windowSoftInputMode="adjustResize"
在清单中声明添加此片段的活动时
使用此布局
检查此布局,它将按预期工作
只需根据需要修改即可
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:background="@color/calendar_background_color"
android:orientation="vertical"></LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/dialog_recycler_view"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_above="@+id/edit_query"
android:layout_below="@+id/toolbar"></android.support.v7.widget.RecyclerView>
<EditText
android:id="@+id/edit_query"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="@color/color_orange_event_text" />
请参见下面的聊天室布局示例
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:clickable="true"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
<LinearLayout
android:id="@+id/linearSmsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:paddingBottom="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginBottom="10dp"
android:layout_marginLeft="120dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/ic_msg_icon_sender"
android:text="This is long text for testing only. This is long text for testing only. This is long text for testing only. This is long text for testing only. This is long text for testing only." />
<TextView
android:id="@+id/txtReceiveMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="120dp"
android:layout_marginTop="10dp"
android:background="@drawable/ic_msg_icon_receiver"/>
</LinearLayout>
</ScrollView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/grey_400" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<EditText
android:id="@+id/edtTxtSmsText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@color/grey_400"
android:hint="Write a message..."
android:padding="10dp" />
<ImageView
android:id="@+id/btnSendSms"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:src="@drawable/ic_send_red" />
</LinearLayout>
</LinearLayout>
并在android文件中使用android:WindowsOfInputMode=“adjustResize”
没有键盘
用键盘
试试这个:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:id="@+id/llFrame">
<include
android:id="@+id/tool"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/White"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewChat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:layout_below="@+id/tool"
android:scrollbars="vertical"
android:dividerHeight="0dp"
android:paddingBottom="10dp"
android:layout_marginTop="5dp"/>
<LinearLayout
android:id="@+id/form"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:background="#91f1f1f1"
android:orientation="horizontal"
android:paddingBottom="2dp"
android:gravity="center">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
>
<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
/>
</LinearLayout>
<TextView
android:id="@+id/tvSendMessage"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:text="Send"
android:layout_gravity="center"
android:gravity="center"
/>
</LinearLayout>
</RelativeLayout>
请在GitHub上查看此库:
我不能使用Scroll view,因为我在这里使用Recyclerview加载所有聊天信息。但我如何在Scroll view中使用Recyclerview?然后将其设为嵌套滚动视图@JayVyastry android:WindowsOfInputMode=“stateHidden”删除作为父级的FrameLayout,并将其替换为LinearLayout垂直方向。我也尝试了Linear layout。@Divyesh我不能使用sateHidden,否则它不允许我打开键盘这不是它。你仍然可以使用键盘。先试试Android:WindowsOfInputMode=“adjustNothing”试试这个。如果我试试这个,它就不会把布局向上推。但即使编辑文本也不例外。键盘用于编辑文本并使其不可见为什么要使用framelayout作为父项?只需将其替换为LinearLayout一次,然后进行检查。我也尝试过使用linear layout,但没有成功。您可以发布您面临的问题的屏幕截图吗?仍然不工作,我正在使用这行代码删除状态栏,requestWindowFeature(Window.FEATURE\u NO\u TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,WindowManager.LayoutParams.FLAG_全屏);也许这就是问题所在,如果我删除这行,那么我就无法获得全屏显示,我不希望状态栏出现在这里
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:id="@+id/llFrame">
<include
android:id="@+id/tool"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/White"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewChat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:layout_below="@+id/tool"
android:scrollbars="vertical"
android:dividerHeight="0dp"
android:paddingBottom="10dp"
android:layout_marginTop="5dp"/>
<LinearLayout
android:id="@+id/form"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:background="#91f1f1f1"
android:orientation="horizontal"
android:paddingBottom="2dp"
android:gravity="center">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
>
<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
/>
</LinearLayout>
<TextView
android:id="@+id/tvSendMessage"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:text="Send"
android:layout_gravity="center"
android:gravity="center"
/>
</LinearLayout>
</RelativeLayout>