透明状态栏导致windowSoftInputMode:adjustResize失效问题
2018-01-04 18:41
1056 查看
当我们通过下面代码:
设置状态栏透明,当界面存在EditText时,在activity里面设置windowSoftInputMode:adjustResize 无效,软键盘依然会遮挡住EditText的焦点位置。
通过下面方式可以解决,大致解决思路是,通过监听视图树的变化,然后把界面滑动到软键盘的上面。
然后在setContentView()方法之后调用WindowSoftModeAdjustResizeExecutor.(this) 就ok了。
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
设置状态栏透明,当界面存在EditText时,在activity里面设置windowSoftInputMode:adjustResize 无效,软键盘依然会遮挡住EditText的焦点位置。
通过下面方式可以解决,大致解决思路是,通过监听视图树的变化,然后把界面滑动到软键盘的上面。
public class WindowSoftModeAdjustResizeExecutor { // For more information, see https://code.google.com/p/android/issues/detail?id=5497 // To use this class, simply invoke assistActivity() on an Activity that already has its content view set. // CREDIT TO Joseph Johnson (http://stackoverflow.com/users/341631/joseph-johnson) for publishing the original Android solution on stackoverflow.com public static void assistActivity(Activity activity) { new WindowSoftModeAdjustResizeExecutor(activity); } private View mChildOfContent; private int usableHeightPrevious; private FrameLayout.LayoutParams frameLayoutParams; private WindowSoftModeAdjustResizeExecutor(Activity activity) { FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content); mChildOfContent = content.getChildAt(0); mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { possiblyResizeChildOfContent(); } }); frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams(); } private void possiblyResizeChildOfContent() { int usableHeightNow = computeUsableHeight(); if (usableHeightNow != usableHeightPrevious) { int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight(); int heightDifference = usableHeightSansKeyboard - usableHeightNow; frameLayoutParams.height = usableHeightSansKeyboard - heightDifference; mChildOfContent.requestLayout(); usableHeightPrevious = usableHeightNow; } } private int computeUsableHeight() { Rect r = new Rect(); mChildOfContent.getWindowVisibleDisplayFrame(r); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return (r.bottom - r.top); } return r.bottom; } }
然后在setContentView()方法之后调用WindowSoftModeAdjustResizeExecutor.(this) 就ok了。
相关文章推荐
- Android-状态栏透明导致android:windowSoftInputMode属性失效
- 安卓开发中将activity设成translucent导致输入法遮挡edittext,windowSoftInputMode设置无效问题
- android:windowSoftInputMode="adjustResize" >
- windowSoftInputMode属性介绍及设置adjustResize不起作用的解决方案
- 你知道android:windowSoftInputMode="adjustResize" 与adjustPan的区别吗
- Android使用ActivityGroup设置android:windowSoftInputMode失效的问题
- Android使用ActivityGroup设置android:windowSoftInputMode失效的问题
- Android使用ActivityGroup设置android:windowSoftInputMode失效的问题
- Android 适配toolbar后windowSoftInputMode="adjustResize" 不生效
- Android4.4设置windowSoftInputMode失效问题的解决方案
- android:windowSoftInputMode属性详解 避免输入法面板遮挡问题
- Android 软键盘遮挡问题 windowSoftInputMode
- Android SoftInputMode为SOFT_INPUT_ADJUST_RESIZE(adjustResize)时没有resize动画的问题
- android:windowSoftInputMode属性详解之解决搜索框获得焦点的时软键盘就会弹出把我底部的tab导航挤出问题
- editText android:windowSoftInputMode="adjustPan"模式下第二次点击editText软键盘覆盖输入框的解决方案
- android设置全屏时,windowSoftInputMode设置无效,软键盘遮挡问题
- 在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan" 可以让界面不被弹出的键盘挤上去。
- 【小知识点总结】android:windowSoftInputMode属性详解 和 按back键直接退出Activity,不关闭软键盘的问题
- 在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan" 可以让界面不被弹出的键盘挤上去。
- android:windowSoftInputMode属性详解(解决软键盘弹出布局调整问题)