开发者

How to show the soft keyboard on device with hard keyboard when hkbd is closed?

开发者 https://www.devze.com 2023-02-21 20:33 出处:网络
I have the corollary question to my first (solved) question, SO Android show softkeybard ... With the sliding keyboard closed, I want my activity to show the keyboard when it gets started.

I have the corollary question to my first (solved) question, SO Android show softkeybard ...

With the sliding keyboard closed, I want my activity to show the keyboard when it gets started.

The same manifest should apply with "stateVisible" set in the manifest for my activity. Do I need any explicit code with the InputMethodManger? Again, I have experimented with the obvious methods and flags, but it does not open the keyboard on the phones with sliding keyboards.

The manifest is copied here for convenience:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mycompany.android.studyIme"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".StudyImeActivity"
                  android:label="@string/app_name" 
                  android:windowSoftInputMode="stateAlwaysVisible|stateVisible">
            <i开发者_开发百科ntent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>


My colleague solved the issue. Instead of trying to force-show, she demonstrated the solution with the "toggle" method.

 InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
 imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 

Of course, you might want to wrap this inside a configuration check of the state of the keyboard.

0

精彩评论

暂无评论...
验证码 换一张
取 消