日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

安卓 android:windowsoftinputmode,Android:windowSoftInputMode="adjustResize"无效解决方法

發布時間:2024/1/23 Android 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安卓 android:windowsoftinputmode,Android:windowSoftInputMode="adjustResize"无效解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Android:windowSoftInputMode="adjustResize"無效解決方法

時間:2018-08-16?????來源:未知

Android開發中用到軟鍵盤時會出現設置Activity的windowSoftInputMode="adjustResize"失效的問題,這時我們可以在activity的根布局上添加fitsSystemWindows="true",然后adjustResize屬性就會起作用。但是這樣做還有一個問題,我們的Actionbar會下移一段距離,這段距離的高度相當于狀態欄的高度。那么我們該如何解決這個問題,完美使用android adjustresize屬性呢?

解決這個問題我們需要自定義一個layout做我們的根布局,在layout中重寫fitSystemWindows()和onApplyWindowInsets()方法,具體如下:

public class MyLinearLayout extends LinearLayout{

private int[] mInsets = new int[4];

public MyLinearLayout(Context context) {

super(context);

}

public MyLinearLayout(Context context, AttributeSet attrs) {

super(context, attrs);

}

public MyLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)

public MyLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {

super(context, attrs, defStyleAttr, defStyleRes);

}

@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);

}

@Override

public final WindowInsets onApplyWindowInsets(WindowInsets insets) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {

mInsets[0] = insets.getSystemWindowInsetLeft();

Log.e("mInsets[0]",""+mInsets[0]);

mInsets[1] = insets.getSystemWindowInsetTop();

Log.e("mInsets[1]",""+mInsets[1]);

mInsets[2] = insets.getSystemWindowInsetRight();

Log.e("mInsets[2]",""+mInsets[2]);

return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0,

insets.getSystemWindowInsetBottom()));

} else {

return insets;

}}}

經過以上的操作之后,就可以很完美的解決windowSoftInputMode="adjustResize"無效問題了,分享就到這里,如果對大家有所幫助,請繼續關注我們,我們會持續更新更多優質技術文章!

總結

以上是生活随笔為你收集整理的安卓 android:windowsoftinputmode,Android:windowSoftInputMode="adjustResize"无效解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。