LoginSignup
8
9

More than 5 years have passed since last update.

windowTranslucentStatusとadjustResizeを同居させるとKitKat以降でトラブる話

Last updated at Posted at 2016-10-19

直面した問題

Themeにandroid:windowTranslucentStatus=trueを指定してActivityをフルスクリーンにした。
ソフトウェアキーボードが表示されたときはActivityの下側がキーボードに隠れてしまわないようにandroid:windowSoftInputMode="adjustResize"を指定し、Activityがリサイズされるようにしたかった。
でもadjustResizeの指定では思ったようにリサイズされなかった。

行き着いた情報

わかったこと

KITKAT以降で導入されたandroid:windowTranslucentStatus=trueを使う場合はActivityはステータスバーやソフトウェアキーボードに関係なく画面いっぱいに広がる。
ステータスバーやソフトウェアキーボードの高さはWindowInsetsを経由して取得できるので、必要ならそれを使ってViewの表示領域を自分で調整すると巧く行く。

ViewCompat.setOnApplyWindowInsetsListener(rootView, new OnApplyWindowInsetsListener() {
    Rect originalPadding;
    @Override
    public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
        if (originalPadding == null) {
            originalPadding = new Rect(v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(), v.getPaddingBottom());
        }
        int t = insets.getSystemWindowInsetTop();
        int b = insets.getSystemWindowInsetBottom();
        v.setPadding(originalPadding.left, originalPadding.top + t, originalPadding.right, originalPadding.bottom + b);
        return insets;
    }
});

悲しかったこと

この問題はwindowTranslucentStatusにまつわる設計変更か、パラダイムの変更があったんだろうと思った。
それは別に良いんだけど Issue 63777: Keyboard don't resize the screen when android:windowTranslucentStatus=true でコメント無くObsoleteになったから皆どうしたら良いかわからず迷走してるとコメント見て感じた。

8
9
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9