SOFT_INPUT_ADJUST_RESIZE

本文探讨了在Android应用中使用全屏WebView时遇到的软键盘遮挡输入框的问题。通过去除Activity的全屏设置,成功解决了键盘遮挡输入框的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

嵌一个webview 然后在输入框调出 android 软键盘时 一直 被覆盖。


各种调整参数设置了没用。。。


1、有把android:windowSoftInputMode="stateHidden|adjustResize“


2、在webview 外嵌套 一个scroll


3、在webview外嵌套 Linearlayout


种种办法都尝试过,但是效果不大。全屏的窗口下面 会忽略 SOFT_INPUT_ADJUST_RESIZE  ,不会进行调整。。


Window flag: hide all screen decorations (such as the status bar) while this window is displayed. This allows the window to use the entire display space for itself -- the status bar will be hidden when an app window with this flag set is on the top layer. A fullscreen window will ignore a value of SOFT_INPUT_ADJUST_RESIZE for the window's softInputMode field; the window will stay fullscreen and will not resize.


意思是说


全屏的窗口下面 会忽略 SOFT_INPUT_ADJUST_RESIZE  ,不会进行调整。。


回想之下 ,我的webview 所在的activity 就是设置的全屏。。。
断然去掉 全屏设置,结果一切正常!
package com.ailuxi.luxitrans; import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.Button; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { private EditText textInputEditText; private Button recordButton; private boolean isTextMode = true; // 默认文字模式 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN ); setContentView(R.layout.activity_main); SoftHideKeyBoardUtil(this); } // // 在onCreate()中调用 // public static void assistActivity(Activity activity) { // SoftHideKeyBoardUtil(activity); // } private View mChildOfContent; private int usableHeightPrevious; private void SoftHideKeyBoardUtil(Activity activity) { FrameLayout content = activity.findViewById(android.R.id.content); mChildOfContent = content.getChildAt(0); mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(this::possiblyResizeChildOfContent); } private void possiblyResizeChildOfContent() { int usableHeightNow = computeUsableHeight(); if (usableHeightNow != usableHeightPrevious) { int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight(); int heightDifference = usableHeightSansKeyboard - usableHeightNow; if (heightDifference > (usableHeightSansKeyboard / 4)) { // 键盘弹出时调整布局高度 mChildOfContent.getLayoutParams().height = usableHeightSansKeyboard - heightDifference; } else { // 键盘收起时恢复高度 mChildOfContent.getLayoutParams().height = usableHeightSansKeyboard; } mChildOfContent.requestLayout(); usableHeightPrevious = usableHeightNow; } } private int computeUsableHeight() { Rect rect = new Rect(); mChildOfContent.getWindowVisibleDisplayFrame(rect); return rect.bottom - rect.top; } } 确实生效了但是键盘弹出时布局跟键盘之间有空隙如何适配
最新发布
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值