Android ScrollView包裹EditText 軟鍵盤彈出后,ScrollView 無法滾動(dòng)

一般用法

  • 設(shè)置屬性:
 android:windowSoftInputMode="stateVisible|adjustResize"
 android:fitsSystemWindows="true"

以上做法會(huì)導(dǎo)致toolbar向下平移了statusbar的高度,也就是說statusbar是全白的。。

解決辦法:

  1. 自定義CustomInsetsFrameLayout
public class CustomInsetsFrameLayout extends FrameLayout{
    private int[] mInsets = new int[4];

    public CustomInsetsFrameLayout(@NonNull Context context) {
        super(context);
    }

    public CustomInsetsFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomInsetsFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    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);
    }
}
  1. 設(shè)置屬性
 android:windowSoftInputMode="stateVisible|adjustResize"
 android:fitsSystemWindows="true"

完美適配!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,811評(píng)論 25 708
  • 1、通過CocoaPods安裝項(xiàng)目名稱項(xiàng)目信息 AFNetworking網(wǎng)絡(luò)請(qǐng)求組件 FMDB本地?cái)?shù)據(jù)庫組件 SD...
    陽明AGI閱讀 16,003評(píng)論 3 119
  • 今天忙忙叨叨一天,掐指一算,好像有一個(gè)月的時(shí)間沒像今天這樣慌亂了,其實(shí)也沒亂到哪里去。 天氣晴的厲害,太陽出乎意料...
    楊柳小苗兒閱讀 436評(píng)論 2 1
  • 人有十二個(gè)感覺,最初期的四個(gè)感覺是在很小的時(shí)候發(fā)展的,它們是觸覺、生命覺、自我移動(dòng)覺、平衡覺。我回憶我的生命覺發(fā)展...
    朵朵頤閱讀 601評(píng)論 1 4
  • 一、管理篇 1、成在經(jīng)營,敗在管理。 2、信任+壓力=快速提升。 3、忠誠創(chuàng)造了忠誠,信任創(chuàng)造了信任,友誼締結(jié)了友...
    商業(yè)思維客棧閱讀 375評(píng)論 0 0