簡體   English   中英

強制鍵盤顯示在屏幕上

[英]Force keyboard to show on a screen

我需要在沒有EditText的屏幕上顯示軟鍵盤-只是鍵盤。 我對可以由軟鍵盤控制的游戲有一個想法,但是我在stackoverflow上發現的內容-不能正常工作。

這是我的game.xml-這是該應用程序主要活動的布局:

<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>

這是在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);

這僅適用於縱向/垂直方向,不適用於橫向/水平方向。

(以防萬一,我的Game類正在擴展View類,並且正在使用畫布)

但是我需要在水平模式下顯示它。

還有另一種方法可以使鍵盤保持在屏幕上:

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

但這沒什么用

因此,在橫向模式下,我需要將軟鍵盤貼在屏幕上

嘗試在單獨的read中執行以下代碼。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM