我有一个处于全屏布局的活动(处于缺口(显示切口)模式)。我想要以下行为:
我尝试在Android清单中添加android:windowSoftInputMode="adjustResize"
,并且在活动布局中以 ScrollView 开始。
问题是:如果将android:fitsSystemWindows="true"
添加到ScrollView中,我将获得正确的行为,但活动将从全屏模式退出。
如何保存全屏陷波模式以达到正确的效果?
我的Android清单:
<activity
android:name=".viewmodel.activities.account.PasswordRequestActivity"
android:label="@string/app_label"
android:screenOrientation="portrait"
android:theme="@style/AppThemeFlatColor"
android:windowSoftInputMode="adjustResize"/>
我的活动布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="122dp"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:background="@color/solid_white">
<Button
android:id="@+id/requestpassword"
android:layout_width="match_parent"
android:layout_height="60dp"
android:textAllCaps="true"
android:layout_alignParentBottom="true"
android:background="@drawable/esg1a"
android:onClick="doForgotPasswordRequest"
android:text="@string/forgot_password_btn"
android:textColor="@color/default_color"
android:textAppearance="@style/TextAppearance.abc.Regular"
android:textSize="13sp"
android:contentDescription="@string/accessibility_requestpassword"/>
<RelativeLayout
android:id="@+id/layoutInsertMail"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_above="@id/requestpassword"
android:background="@drawable/esg3a">
<ImageView
android:id="@+id/iconmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:src="@drawable/esb_icon_mail"/>
<EditText
android:id="@+id/requestEmail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="@id/iconmail"
android:layout_marginStart="20dp"
android:ems="10"
android:background="@null"
android:hint="@string/login_email_hint"
android:textSize="13sp"
android:inputType="textEmailAddress"
android:textAppearance="@style/TextAppearance.abc.Regular"
android:contentDescription="@string/accessibility_emailrecoverpassword"/>
</RelativeLayout>
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_above="@id/bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@android:color/transparent" />
<View
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#BF000000"
android:visibility="gone"
android:layout_above="@id/bottom"/>
</RelativeLayout>
</ScrollView>
在我的v28 styles.xml中,添加到AppThemeFlatColor主题:
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
找到解决方案
将以下代码添加到活动中:
@Override
protected void onResume() {
super.onResume();
ViewCompat.setOnApplyWindowInsetsListener(getWindow().getDecorView(), (view, insets) ->
ViewCompat.onApplyWindowInsets(getWindow().getDecorView(),
insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), 0,
insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()))
);
}
并添加到ScrollView:
android:fitsSystemWindows="true"