android adjustresize not working when using windowTranslucentStatus,解决全屏效果与输入框属性冲突的问题
来源:互联网 发布:软件开发需要学习什么 编辑:程序博客网 时间:2024/04/29 16:13
做项目的时候,用沉浸式状态栏,最终实现的效果如下:
上图中是一个聊天界面,当输入法弹出的时候需要把Editteext顶起,本来把Edittext顶起这是一件多么简单的事,只需要在manifest清单文件设置<android:windowSoftInputMode="adjustResize">就可以了,然而当我适配完沉浸式状态栏后,兴致勃勃地运行项目一看,妈的傻眼了,竟然出现了下图这种情况:
是的,你没看错,ToolBar竟然往下跑了,Edittext也没有被弹起。我当时还怀疑没运行成功,又运行了几遍,没想到还是一样的结果,又检查了几遍代码,确定这样写没错后,就立马google了起来,不搜不知道,一搜吓一跳,网上一大堆这种问题,看来不少人都踩了这坑,然后找到了解决方法:windowsoftinputmode-adjustresize-not-working-with-translucen
下面这个是在webView的界面显示:
解决后的界面:
解决方法就是从写了fitSystemWindows方法,然后将重写的布局作为根布局,再设置fitSystemWindows = true:
- LinearLayout:
/** * 解决activity设置了状态栏透明,又设置了android:windowSoftInputMode="adjustResize"的时候输入框被输入法挡住的情况<br> * 这个作为layout的根布局(root),并设置<code>android:fitsSystemWindows="true"</code> * Created by Awen <Awentljs@gmail.com> */public class CustomInsetsLinearLayout extends LinearLayout { private int[] mInsets = new int[4]; public CustomInsetsLinearLayout(Context context) { super(context); } public CustomInsetsLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); } public CustomInsetsLinearLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public final int[] getInsets() { return mInsets; } @Override protected final boolean fitSystemWindows(Rect insets) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // Intentionally do not modify the bottom inset. For some reason, // if the bottom inset is modified, window resizing stops working. // TODO: Figure out why. mInsets[0] = insets.left; mInsets[1] = insets.top; mInsets[2] = insets.right; insets.left = 0; insets.top = 0; insets.right = 0; } return super.fitSystemWindows(insets); }}
布局文件:
<?xml version="1.0" encoding="utf-8"?><com.demo.widget.insets.CustomInsetsLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:fitsSystemWindows="true" android:orientation="vertical"> <-- main content,这里是你的主要内容--></com.demo.widget.insets.CustomInsetsLinearLayout>
如果需要用到RelativeLayout或FrameLayout的,把上面的继承父类改为RelativeLayout或FrameLayout就可以了。
另外,贴上一个Android键盘面板冲突 布局闪动处理方案,也就是输入法跟表情切换顺畅,跟微信一样,这个解决方法也是微信团队的人出品的,非常感谢,在这里我也要分享下给大家,因为我发现还有很多app都没解决这个问题
最后祝大家周末愉快。
文/八进制(简书作者)
原文链接:http://www.jianshu.com/p/4f744c95a51c
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
原文链接:http://www.jianshu.com/p/4f744c95a51c
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
0 0
- android adjustresize not working when using windowTranslucentStatus,解决全屏效果与输入框属性冲突的问题
- Android全屏和adjustResize的冲突解决
- Android adjustresize全屏无效问题
- 解决安卓全屏“FLAG_FULLSCREEN”状态下“adjustResize”失效,全屏状态下WebView的输入框被软键盘挡住的问题
- 解决安卓全屏“FLAG_FULLSCREEN”状态下“adjustResize”失效,全屏状态下WebView的输入框被软键盘挡住的问题
- 解决android 软键盘在全屏下设置adjustResize无效的问题
- 解决android 软键盘在全屏下设置adjustResize无效的问题
- android studio下“HAX is not working...”问题的解决
- android 软键盘在全屏下设置adjustResize无效的问题
- Android中windowTranslucentStatus与windowTranslucentNavigation的一些设置
- Android OnSensorChanged() not working when screen lock is on
- android中的windowTranslucentStatus和fitsSystemWindows的作用
- Android 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 关于设置全屏后与屏蔽Home键的冲突问题,盛传的几种做法,未解决!
- 解决Android webview 全屏模式下键盘遮挡输入框问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 工作效率总是低下,为什么呢
- Lua 循环学习
- pythonの鉴黄之路(二)——图片转base64码
- Android开发:shape和selector和layer-list的(详细说明
- 用Eclipse 开发Dynamic Web Project应用程序
- android adjustresize not working when using windowTranslucentStatus,解决全屏效果与输入框属性冲突的问题
- redis mem_fragmentation_ratio 过大
- 彻底理解Java动态代理
- @po附近有语法错误
- mysql中group by 和 group_concat()的区别
- facet与compiler不匹配
- 大数据下的用户行为分析
- jQuery mobile dialog 详情
- java 工具类(将数据导入数据库)