2012-10-29 93 views
0

我正在使用AndEngine進行遊戲,該遊戲使用設備的軟鍵盤。我不是EditText,而是我自己的。我試圖檢測軟鍵盤上的按鍵, 我已經成功地在AndEngine場景中顯示和隱藏鍵盤。軟鍵盤聽衆

我的活動實現了OnKeyboardActionListener,我讀用作軟鍵盤監聽,但我不知道如何與this類(活動)註冊的鍵盤。 顯然,此刻,裏面onPress()的代碼是沒用..

我找不到任何的例子,他們大多是指EditText,這我沒有使用.. 這可能嗎? 也許服務還是什麼?

在此先感謝。

編輯:

我試圖創建一個使用KeyboardView和一個自定義Keyboard, 這樣我自己的鍵盤,我可以做

KeyboardView kbView = new KeyboardView(this,null); 
kbView.setKeyboard(new Keyboard(this, R.xml.keyboard); 
kbView.setOnKeyboardActionListener(new OnKeyboardActionListener() { 
    .... 
} 

有沒有人這樣做呢?作品,不?

謝謝。

+0

您可以發佈您的相關代碼部分嗎? – Ridcully

+0

什麼部分是相關的? –

回答

1

我結束了創建我自己的KeyboardKeyboard View`,然後我用這個代碼

CustomKeyboardView kbView = (CustomKeyboardView) findViewById(R.id.keyboard_view); 
kbView.setKeyboard(new Keyboard(this, R.xml.myCustomKeyboard); 
kbView.setOnKeyboardActionListener(new OnKeyboardActionListener() { 
    @Override 
    public void onPress(int primaryCode) { 
     // A Key was pressed 
    } 
    .... 
} 

而在XML佈局

<pathToCustomKeyboardView.CustomKeyboardView 
    android:id="@+id/keyboard_view" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:visibility="gone" 
    android:layout_alignParentBottom="true" /> 

CustomKeyboardView只延伸KeyboardView創造了一個KeyboardView,不知道爲什麼,但它適用於定製版本而不適用於原版

編輯: 此外,該活動延伸SimpleLayoutGameActivity,然後我選擇了包含CustomKeyboardView的佈局