Android EditText悬浮在输入法之上
Android EditText悬浮在输入法之上
使用
android:windowSoftInputMode="adjustResize"会让界面整体被顶上去,很多时候我们不需要这样的情况出现,这里给出另一个方案.
**思路:监听输入法的状态,然后动态的滚动
EditText所在的ViewGroup或者View**
1. Android Manifest.xml
<activity
android:name=".InputActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:configChanges="keyboard|keyboardHidden|orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"> //非adjustResize
</activity>
2. 布局文件
<RelativeLayout
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">
<LinearLayout
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">
<EditText
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"/>
<TextView
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"/>
</LinearLayout>
</RelativeLayout>
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. 不做处理前:

2. 处理后的效果:

Android EditText悬浮在输入法之上的更多相关文章
- 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 EditText不弹出输入法总结,焦点问题的总结
看一个manifest中Activity的配置,如果这个页面有EditText,并且我们想要进入这个页面的时候默认弹出输入法,可以这样设置这个属相:android:windowSoftInputMod ...
- Android WindowManager悬浮窗:不需要申请权限实现悬浮
Android WindowManager悬浮窗:不需要申请权限实现悬浮 附录文章1介绍了Android平台上的悬浮窗WindowManager,WindowManager悬浮窗可以悬浮在And ...
- Android EditText属性
1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password="true" // 以”.”形式显示文本 ( ...
随机推荐
- Linux学习笔记(9)-守护进程
明天学这个!! ---------------------------------------------------------- 守护进程(Daemon)是运行在后台的一种特殊进程.它独立于控制终 ...
- mysql优化
一.优化事项 1. 数据库(表)设计合理 (不合理设计导致内伤) 我们的表设计要符合3NF 3范式(规范的模式) , 有时我们需要适当的逆范式.2. sql语句的优化(索引,常用小技巧 ...
- Linux Shell 流程控制语句
* 本文主要介绍一些Linux Shell 常用的流程控制语句* 1. if 条件语句:if-then/if-elif-fi/if- else-fi if [条件判断逻辑1];then command ...
- jQuery.lazyload
Lazy Load延迟加载也有的称为惰性加载,是一个用 JavaScript 编写的 jQuery 插件. 它可以延迟加载长页面中的图片. 在浏览器可视区域外的图片不会被载入, 直到用户将页面滚动到它 ...
- 51Nod 1010 只包含因子2 3 5的数 Label:None
K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...
- 【BFS】HDU 1495
直达–> HDU 1495 非常可乐 相似题联动–>POJ 3414 Pots 题意:中文题,不解释. 思路:三个杯子倒来倒去,最后能让其中两个平分即可.可能性六种.判定的时候注意第三个杯 ...
- APP设计资源
在开发独立客户端时,需要一些不同尺寸的图标和图片,统计如下. APP 图标 ICON iOS:(主要需要这三类图标) 58x58 87x87 (Spotlight & Settings) 80 ...
- java学习-关于字符串String
有必要总结记录一下java的学习,否则,永远只是记忆碎片化和always google(费时) 刚好,小伙伴给了一份自己做的review,在学习的过程中,update一下自己的见解和学习内容: 关于S ...
- svn 应该忽略的文件(visual studio)
*.o *.lo .la ## .*.rej .rej .~ ~ .# .DS_Store thumbs.db Thumbs.db *.bak *.class *.exe *.dll *.mine * ...
- TortoiseSVN 合并操作简明教程
下列步骤展示了如何将分支A中的修改合并到分支B. 1.在分支B的本地副本目录中选择"合并(Merge)". 2.选择“合并一个版本范围(Merge a range of revis ...