Android Activity 键盘弹出 布局重新分配空间
2018-02-24 15:59
344 查看
在 manifest 中 设置:
android:windowSoftInputMode="stateHidden|adjustResize"或者代码中设置:getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);在setContentView()之前调用
SOFT_INPUT_ADJUST_NOTHING: 不调整(输入法完全直接覆盖住,未开放此参数)SOFT_INPUT_ADJUST_PAN: 把整个Layout顶上去露出获得焦点的EditText,不压缩多余空间SOFT_INPUT_ADJUST_RESIZE: 整个Layout重新编排,重新分配多余空间SOFT_INPUT_ADJUST_UNSPECIFIED: 系统自己根据内容自行选择上两种方式的一种执行(默认配置)
但是当状态栏设置为透明的时候 会失效:
解决办法 重写xml 的跟布局 public class TMResizeLinearLayout extends LinearLayout {
private int[] mInsets = new int[4];
public TMResizeLinearLayout(Context context) {
super(context);
}
public TMResizeLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TMResizeLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public final int[] getInsets() {
return mInsets;
}
/**
* 此方法以过期,当应用最低API支持为20后,可以重写以下方法
*
* @Override * 未测试……
*/
public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
4000
mInsets[0] = insets.getSystemWindowInsetLeft();
mInsets[1] = insets.getSystemWindowInsetTop();
mInsets[2] = insets.getSystemWindowInsetRight();
return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0,
insets.getSystemWindowInsetBottom()));
} else {
return insets;
}
}
@Override
protected final boolean fitSystemWindows(Rect insets) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
mInsets[0] = insets.left;
mInsets[1] = insets.top;
mInsets[2] = insets.right;
return super.fitSystemWindows(insets);
} else {
return super.fitSystemWindows(insets);
}
}
}在xml中引用
需要在属性中 设置:android:fitsSystemWindows="true"否则不会生效
android:windowSoftInputMode="stateHidden|adjustResize"或者代码中设置:getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);在setContentView()之前调用
SOFT_INPUT_ADJUST_NOTHING: 不调整(输入法完全直接覆盖住,未开放此参数)SOFT_INPUT_ADJUST_PAN: 把整个Layout顶上去露出获得焦点的EditText,不压缩多余空间SOFT_INPUT_ADJUST_RESIZE: 整个Layout重新编排,重新分配多余空间SOFT_INPUT_ADJUST_UNSPECIFIED: 系统自己根据内容自行选择上两种方式的一种执行(默认配置)
但是当状态栏设置为透明的时候 会失效:
解决办法 重写xml 的跟布局 public class TMResizeLinearLayout extends LinearLayout {
private int[] mInsets = new int[4];
public TMResizeLinearLayout(Context context) {
super(context);
}
public TMResizeLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TMResizeLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public final int[] getInsets() {
return mInsets;
}
/**
* 此方法以过期,当应用最低API支持为20后,可以重写以下方法
*
* @Override * 未测试……
*/
public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
4000
mInsets[0] = insets.getSystemWindowInsetLeft();
mInsets[1] = insets.getSystemWindowInsetTop();
mInsets[2] = insets.getSystemWindowInsetRight();
return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0,
insets.getSystemWindowInsetBottom()));
} else {
return insets;
}
}
@Override
protected final boolean fitSystemWindows(Rect insets) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
mInsets[0] = insets.left;
mInsets[1] = insets.top;
mInsets[2] = insets.right;
return super.fitSystemWindows(insets);
} else {
return super.fitSystemWindows(insets);
}
}
}在xml中引用
需要在属性中 设置:android:fitsSystemWindows="true"否则不会生效
相关文章推荐
- 当 Activity 以全屏模式运行时,如何允许 Android 系统状态栏在顶层出现,而不迫使 Activity 重新布局让出空间?
- 当 Activity 以全屏模式运行时,如何允许 Android 系统状态栏在顶层出现,而不迫使 Activity 重新布局让出空间
- Android弹出键盘布局闪动原理和解决
- Android软键盘弹出时把布局控件顶上去的解决方法
- Android软键盘弹出时使布局上移,避免软键盘覆盖提交等按钮
- Android 禁止进入activity自动弹出键盘
- Android软键盘弹出时把布局顶上去的解决方法
- Android软键盘弹出时把布局顶上去的解决方法
- Android软键盘弹出,RelativeLayout 布局会把原来的界面挤上去
- Android软键盘弹出不影响布局的方…
- Android软键盘弹出时把布局顶上去的解决方法
- 键盘弹出以后Activity的布局方式
- Android透明状态栏,弹出键盘布局诡异的解决方案
- Android软键盘弹出,界面布局整体上移
- Android软键盘弹出时把布局顶上去的解决方法
- 软键盘弹出后重新布局(把布局向上顶)
- Android中软键盘弹出时关于布局的问题
- Android:不让 EditText 在 Activity 中自动弹出键盘
- 在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan" 可以让界面不被弹出的键盘挤上去。
- Android 软键盘弹出时布局内指定内容上移实现及问题解决