Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect soft input visibility and height when using fullscreen mode

I've read multiple posts of this issue and the solution was to use OnGlobalLayoutListener. Problem here is that my application has declared following in manifest:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

So the inputmode adjust doesn't work and I cant use OnGlobalLayoutListener

How to get the event that soft input is visible/gone, and I would also need to get the height of input as well to adjust my current layout bottomMargin.

Thanks.

like image 859
Niko Avatar asked Nov 13 '22 07:11

Niko


1 Answers

I don't know how you use OnGlobalLayoutListener but it works fine in my code below:

        final View activityRootView = findViewById(R.id.container);
        final ViewTreeObserver observer = activityRootView
                .getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {

                Rect r = new Rect();
                // r will be populated with the coordinates of your view
                // that area still visible.
                activityRootView.getWindowVisibleDisplayFrame(r);
                int heightDiff = activityRootView.getRootView().getHeight()
                        - (r.bottom - r.top);
                Toast.makeText(TestActivity.this, String.valueOf(heightDiff),
                        Toast.LENGTH_SHORT).show();

            }
        });

THe above code is in onResume() of my TestActivity with the theme @android:style/Theme.NoTitleBar.Fullscreen

layout file for the view:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="aaa" />

</LinearLayout>

The activity config in menifest:

<activity
    android:name=".ui.activity.TestActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
like image 143
Bolton Avatar answered Nov 14 '22 23:11

Bolton