1

I try to get softkeyboard status, (shown or hidden) using onConfigurationChanged (here : http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange)

But it doesn't work for me. I have no idea. (also I've already tried hardKeyboardHidden and keyboard-config's value)

Please check my code.

AndroidManifest.xml

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:configChanges="keyboardHidden"
            android:windowSoftInputMode="adjustResize"
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

MainActivity.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // Checks whether a hardware keyboard is available
    if (newConfig.keyboardHidden== Configuration.HARDKEYBOARDHIDDEN_NO) {
        Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
    } else if (newConfig.keyboardHidden== Configuration.HARDKEYBOARDHIDDEN_YES) {
        Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
    }
}

and just simply EditText added in activity_main.xml

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" 
tools:context=".MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

So how to fix this problem ?

Alex Andrei
  • 7,315
  • 3
  • 28
  • 42
bubu uwu
  • 463
  • 2
  • 12
  • 26

2 Answers2

1

This method use onMeasure(). It checks if activity screen is smaller.

How to check visibility of software keyboard in Android?

Community
  • 1
  • 1
Sebastian Schneider
  • 4,896
  • 3
  • 20
  • 47
1

What about the following solution?

InputMethodManager imm = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    if (imm.isAcceptingText()) {
        writeToLog("Software Keyboard is visible");
    } else {
        writeToLog("Software Keyboard is not visible");
    }
Sid
  • 14,176
  • 7
  • 40
  • 48