android 输入法 悬浮窗口,Android EditText悬浮在输入法之上

本文介绍了如何在Android中让EditText悬浮在输入法上方,避免输入法遮挡内容。通过设置`android:windowSoftInputMode="adjustPan"`,并监听输入法状态,动态滚动包含EditText的ViewGroup,实现输入法打开时EditText的自动调整。

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

Android EditText悬浮在输入法之上

使用 android:windowSoftInputMode="adjustResize" 会让界面整体被顶上去,很多时候我们不需要这样的情况出现,这里给出另一个方案.

**思路:监听输入法的状态,然后动态的滚动 EditText 所在的 ViewGroup 或者View **

1. Android Manifest.xml

android:name=".InputActivity"

android:theme="@style/Theme.AppCompat.Light.NoActionBar"

android:configChanges="keyboard|keyboardHidden|orientation"

android:screenOrientation="portrait"

android:windowSoftInputMode="adjustPan"> //非adjustResize

2. 布局文件

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/root"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/bg_saber_q"

tools:context="didikee.com.demoapk.InputActivity">

android:id="@+id/rl_inputdlg_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:background="#00000000"

android:orientation="horizontal">

android:id="@+id/input_message"

android:layout_width="0dp"

android:layout_height="@dimen/dp30"

android:layout_gravity="center|left"

android:layout_marginLeft="@dimen/dp12"

android:paddingLeft="@dimen/dp2"

android:paddingRight="@dimen/dp2"

android:layout_weight="1"

android:background="@drawable/shape_cricle_gray_solid_white"

android:focusable="true"

android:focusableInTouchMode="true"

android:gravity="left"

android:imeOptions="actionSend"

android:maxLength="32"

android:singleLine="true"

android:text=""

android:textColor="@color/dark_text"

android:textSize="20sp"/>

android:id="@+id/confrim_btn"

android:layout_width="@dimen/dp50"

android:layout_height="@dimen/dp30"

android:layout_gravity="center|right"

android:layout_marginLeft="@dimen/dp11"

android:layout_marginRight="@dimen/dp12"

android:background="@drawable/shape_cricle_solid_orange"

android:gravity="center"

android:text="发送"

android:textColor="@color/white"/>

3. Activity里设置监听,滚动 input 视图

public class InputActivity extends AppCompatActivity {

private RelativeLayout rLayout;

private View mInputLayout;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_input);

mInputLayout = findViewById(R.id.rl_inputdlg_view);

rLayout = ((RelativeLayout) findViewById(R.id.root));

//输入法到底部的间距(按需求设置)

final int paddingBottom = DisplayUtil.dp2px(this, 5);

rLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

@Override

public void onGlobalLayout() {

Rect r = new Rect();

rLayout.getWindowVisibleDisplayFrame(r);

//r.top 是状态栏高度

int screenHeight = rLayout.getRootView().getHeight();

int softHeight = screenHeight - r.bottom ;

Log.e("test","screenHeight:"+screenHeight);

Log.e("test","top:"+r.top);

Log.e("test","bottom:"+r.bottom);

Log.e("test", "Size: " + softHeight);

if (softHeight>100){//当输入法高度大于100判定为输入法打开了

rLayout.scrollTo(0, softHeight+paddingBottom);

}else {//否则判断为输入法隐藏了

rLayout.scrollTo(0, paddingBottom);

}

}

});

}

}

效果图:

1. 不做处理前:

L3Byb3h5L2h0dHAvb2FoenJ3MTFuLmJrdC5jbG91ZGRuLmNvbS8vcGljLzIwMTYwODA0aW5wdXRfMi5wbmc=.jpg

2. 处理后的效果:

L3Byb3h5L2h0dHAvb2FoenJ3MTFuLmJrdC5jbG91ZGRuLmNvbS8vcGljLzIwMTYwODA0aW5wdXRfMy5wbmc=.jpg

89、Android EditText 悬浮停靠

package com.willen.topFloatDemo; import android.content.Context; import android.os.Handler; import a ...

Android Edittext聚焦时输入法挡住了EditText输入框的两种解决方案

方案一.把整个布局文件用ScrollView套住.这样当你聚焦时虽然输入法也能够挡住一些输入框,但是你可以通过手动滑动看被挡住的内容. 方案二.在Activity中设置android:windowSo ...

Android EditText 不弹出输入法

当第一次进入一个activity的时候  一般是第一个edittext是默认选中的,但是该死的软键盘也一起弹出来了 那是相当的不美观哈!(#‵′)凸.为此, 本大人就去寻找在刚进入这个activity ...

Android EditText不弹出输入法焦点问题的总结

转自:http://mobile.51cto.com/aprogram-403138.htm 看一个manifest中Activity的配置,如果这个页面有EditText,并且我们想要进入这个页面的 ...

Android EditText自动弹出输入法焦点

http://mobile.51cto.com/aprogram-403138.htm 1. 看一个manifest中Activity的配置,如果这个页面有EditText,并且我们想要进入这个页面的 ...

Android EditText默认不弹出输入法,以及获取光标,修改输入法Enter键的方法

一.Android EditText默认不弹出输入法的办法:1. 在AndroidManifest.xml中将需要默认隐藏键盘的Activity中添加属性即可(常用此方法) android:windo ...

Android WindowManager悬浮窗:不需要申请权限实现悬浮

 Android WindowManager悬浮窗:不需要申请权限实现悬浮 附录文章1介绍了Android平台上的悬浮窗WindowManager,WindowManager悬浮窗可以悬浮在And ...

Android EditText属性

1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password="true" // 以”.”形式显示文本 ( ...

Android 之 悬浮窗

昨天研究Android的悬浮窗,遇到一个问题,研究了一天,总算找到结症了,原因非常坑人..... 问题是这样的,我想要将悬浮窗展现在桌面或其他应用之上,我的开发机子用的是MIUI,结果发现在机子上无论 ...

随机推荐

Codeforces 328A-IQ Test(数列)

A. IQ Test time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

css 定位(fixed > absolute > relative)与层级zIndex 的权限认知

原则1: fixed > absolute > relative原则2: zIndex 越高越牛逼,不管你是谁无视身份.原则3: 青出于蓝而胜于蓝,儿子永远比父亲强原则4: 平台很重要. ...

thinkphp 视图(一)

视图 View <?php namespace app\index\controller; class Index{ public function index(){ return view() ...

airflow-operator 可以管理airflow 的kuberntes 自定义controller &amp&semi;&amp&semi; crd

使用airflow-operator 我们可以让airflow 可以很方便的运行在k8s集群环境中,当前还在开发中 主要分为两部分:airflowbbase && airfowclus ...

json的内容回顾

复习一下json这个模块 import json s = '{"name":"cui","age":12}' # 这里外部必须是单引号,内部 ...

Direct2D教程VI——转换(Transform)

目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...

莫衷一是——i&plus;&plus;&plus;j 该怎样计算?

这是一个有趣的计算, 3 个加号相连.那么,究竟是怎样结合的呢?是依照: i + (++j)来运算,还是依照(i++) + j 来运算呢? 这个问题在相似于 C / C++中讨论是没有多大意义的,由于 ...

hadoop学习笔记(七):Java HDFS API

一.使用HDFS FileSystem详解 HDFS依赖的第三方包: hadoop 1.x版本: commons-configuration-1.6.jar commons-lang-2.4.jar ...

Strust2: 工作流程

以下为Struts2的体系结构图: Struts2框架处理用户请求,大体分为以下几个过程: (1)用户发出一个HttpServletRequest请求 (2)请求经过一系列过滤器,最后达到Filter ...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值