Android 软键盘将工具栏推入顶部状态栏
我已经问了至少十个类似的问题,但似乎什么都不管用 我有一个简单的相对布局,包括工具栏、文本视图、编辑文本等(见下面的xml) 当编辑文本处于焦点时,我需要软键盘将布局向上推,但在工具栏下方(即工具栏被固定),但键盘将整个布局向上推,包括工具栏 我已经尝试过adjustPan、adjustResize、scrollviews等,但没有成功,对此的任何帮助都将不胜感激 布局xml:Android 软键盘将工具栏推入顶部状态栏,android,xml,layout,toolbar,Android,Xml,Layout,Toolbar,我已经问了至少十个类似的问题,但似乎什么都不管用 我有一个简单的相对布局,包括工具栏、文本视图、编辑文本等(见下面的xml) 当编辑文本处于焦点时,我需要软键盘将布局向上推,但在工具栏下方(即工具栏被固定),但键盘将整个布局向上推,包括工具栏 我已经尝试过adjustPan、adjustResize、scrollviews等,但没有成功,对此的任何帮助都将不胜感激 布局xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLa
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.Test">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:id="@+id/appbar_layout"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/appbar_layout">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_title"
android:textSize="25dp"
android:textColor="@color/colorPrimaryDark"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/iv"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/tv_date"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/iv"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tv_title"/>
<ImageView
android:id="@+id/iv"
android:layout_marginRight="-6dp"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentRight="true"
android:maxHeight="150dp"
/>
<TextView
android:id="@+id/tv_description"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/iv"
android:layout_centerHorizontal="true"
android:textSize="15dp"
android:textColor="@color/colorPrimaryDark"/>
<RatingBar
android:id="@+id/rb"
style="?android:attr/ratingBarStyle"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_description"
android:numStars="5" />
<View
android:id="@+id/view"
android:layout_below="@+id/rb"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="1dp"
android:visibility="visible"
android:background="@color/colorPrimary"/>
<EditText
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="@dimen/activity_horizontal_margin"
android:layout_below="@+id/view"
android:gravity="top"
android:background="@android:color/transparent"
/>
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/textColorPrimary"
android:textSize="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
使用折叠工具栏布局
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
并确保将
app:layout\u collapseMode=“pin”
标志添加到layout.xml中的工具栏中。我在片段的onCreate视图上使用此代码,它工作正常
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT\u INPUT\u ADJUST\u RESIZE)代码>我将尝试这两种方法。作为一个选项,您可以将此行添加到清单中: