简体   繁体   中英

Force keyboard to show on a screen

I need the soft keyboard to be shown on a screen whithout an EditText - just a keyboard. I have an idea about a game which would be controlled by a soft keyboard, but what I've found on stackoverflow - doesn't work as it should.

here's my game.xml - it's a layout to main Activity of this app :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/root"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".GameActivity" >

    <com.vladdrummer.textmaster.Game
        android:id="@+id/game"
        android:layout_width="wrap_content"
        android:windowSoftInputMode="adjustResize"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

here's how it's called in Activity :

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);//this suppose to force keyboard to be on screen
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);//чтоб экран не гас

    setContentView(R.layout.game);

this works only in portrait/vertical orientation and don't work in landscape/horizontal.

(In case, my Game class is extending View class and I'm working with canvas)

But I need this to be shown in horizontal mode.

there were another way to keep keyboard onscreen :

((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

but that doesn't do a thing

so,please, I need a soft keyboard to be sticked on a screen, in landscape mode

Try execute the following code in a seperate theread.

  InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  if(im != null)  im.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM