簡體   English   中英

在Android上啟動SoftKeyboard

[英]Bringing up SoftKeyboard on android

我想在用戶按下搜索硬件搜索鍵時彈出軟件鍵盤。

目前,我使用以下功能似乎不適用於搜索鍵,但確實適用於后退鍵:記錄甚至無法通過搜索鍵進行跟蹤。

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK){
            Log.v(TAG, "On back key press");
            renderPrevious();

        return false;
        }
        if(keyCode == KeyEvent.KEYCODE_SEARCH){
            Log.v(TAG, "On search key press");
            this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

        return false;
        }

        return true;
    }

我沒有文本字段,但是想要直接自己處理輸入。

此方法setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)不會喚醒鍵盤。 檢查此鏈接 要了解更多信息,請查看此示例 希望能幫助到你

編輯:

試試這個showSoftInput方法

也許這會有所幫助:

 InputMethodManager inputMgr = (InputMethodManager)getSystemService Context.INPUT_METHOD_SERVICE); 
inputMgr.toggleSoftInput(0, 0);

http://plainoldstan.blogspot.com/2010/09/android-set-focus-and-show-soft.html

“進行實驗時,直到我意識到我應該擁有一個沒有硬件鍵盤的仿真器設備時,我才真正得到想要的東西:”

暫無
暫無

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

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