关于系统Dialog输入法遮挡EditText的问题(无法将EditText移动到输入法上方)

该博客介绍了如何在Android中自定义一个带有EditText的Dialog,并解决当弹出输入法时Dialog被遮挡的问题。通过设置Window的层级为WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY和在Dialog的style中设置windowSoftInputMode为stateVisible|adjustPan,可以确保输入法出现时不覆盖EditText。同时,提供了自定义Dialog的Builder模式实现,允许设置标题、内容、按钮等,并展示了使用示例。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

自定义了一个带EditText系统级的Dialog,在Window中show出来,但是当弹出输入法时将输入框挡住了,严重影响用户体验
需要设置Window的层级为WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
同时需要在Dialog的style样式中设置windowSoftInputMode属性

    <style name="InputDialog" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowSoftInputMode">stateVisible|adjustPan</item>
    </style>

自定义PasswordDialog代码如下:

package com.example.myapplication;


import android.content.Context;

import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;


public class PasswordDialog extends BaseDialog {
   
   

    private TextView mTvTitle;
    private TextView mTvContent;
    private Button mBtnConfirm;
    private Button mBtnCancel;
    private View mHorizontalLine;
    private View mVerticalLine;
    private FrameLayout mContentLayout;


    public PasswordDialog(Context context) {
   
   
        super(context);
    }

    public PasswordDialog(Context context, int theme) {
   
   
        super(context, theme);
    }

    @Override
    protected void initManager() {
   
   

    }

    @Override
    protected int getLayoutId() {
   
   
        return R.layout.dialog_warn;
    }

    @Override
    protected void initView(View view) {
   
   
        mTvTitle = view.findViewById(R.id.tv_dialog_title<

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

言并肃

感谢大哥支持!您的鼓励是我动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值