2012-04-03 137 views
8

我正在做的只是隱藏彈出窗口,顯示當前使用軟鍵盤時按下的按鍵。這可能嗎?我正在創建我自己的新鍵盤,它不需要它們。隱藏Android鍵盤按鍵預覽

從我的理解中,下面的圖片是實際彈出式鍵盤,您可以選擇使用android:popupKeyboardandroid:popupCharactersKeyboard.Key XML中顯示。

Popup Android Keyboards

但下面的圖片是不相同(見this picture)。有沒有辦法關閉,使用XML或甚至編程?

Android Keyboard Popups

回答

14

閱讀a little bit of the actual android keyboard source code後:

我指的是「鍵預覽」,這是「顯示按下的鍵的放大版本,一個彈出窗口。」默認情況下預覽已啓用,但要禁用它,簡單地說就是setPreviewEnabled(boolean previewEnabled)。這是一個從KeyboardView類的方法。 API

+0

喜@Whymarrh如果你已經對自己開發的客戶類中禁用預覽,我也正在softkeyboard其中i我面臨的問題,我想在一個鍵上顯示多個字符,如您在上面的第一個鍵盤q下面顯示1.我已經嘗試過在鍵上顯示多個/多行字符使用標籤,然後我得到了輸出,如此鏈接「http ://puu.sh/4Xmz1.png」。所以你可以請指導如何在鍵上顯示多個字符... – Aniket 2013-10-23 14:10:18

+0

@Aniket你可以在GitHub上在線看到我的完整源代碼:http://git.io/mM7pPQ。您可以嘗試使用Unicode字符來顯示您需要的密鑰,如下所示:http://git.io/SXo3GA。 – Whymarrh 2013-10-23 19:34:21

+0

它爲我工作。我只需要使用「KeyboardView」類中的「setPreviewEnabled(boolean)」方法。 – 2015-07-24 13:05:27

5
public void onPress(int primaryCode) { 
    mInputView.setPreviewEnabled(false); 
} 

public void onRelease(int primaryCode) { 
    mInputView.setPreviewEnabled(true); //Change to false if you want remove too for the Del key when it's pressed 
} 

此外,爲了讓觀點和普遍延伸自InputMethodService

private KeyboardView mInputView; 
    @Override 
    public KeyboardView onCreateInputView() { 
     mInputView = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null); 
     mInputView .setPreviewEnabled(false); 
     return mInputView; 
    }