問題描述
我的 Android 應用中有自定義 鍵盤.xml中描述的布局是這樣的
I have custom keyboard in my app for Android. It's layout described in xml like this
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"">
<Row>
<Key android:keyLabel="F1" android:keyOutputText="F1"/>
<Key android:keyLabel="F2" android:keyOutputText="F2"/>
<Key android:keyLabel="F3" android:keyOutputText="F3"/>
...
所以,我很想知道如何禁用,例如f1"鍵~讓它變灰且不可觸摸.這里有一些類似的問題,但都是關于默認軟知識庫的.
So, i'm insteresting how i can disable, for example 'f1' key ~ make it grey and untouchable. There are some similar questions here, but all about default soft-KB.
我知道我可以像這樣遍歷鍵
I know I can iterate through keys like this
for (Keyboard.Key key : myKeyboard.getKeys())
但它看起來像 Keyboard.Key 類的對象對按鍵外觀的任何變化都無用.
but it's look like objects of Keyboard.Key class are useless for any changes in key's look.
UPD:我沒有找到解決方案.我手動實現了鍵盤——大的相對布局、常用按鈕和自定義按鈕,一切都很好.順便說一句 - 自定義鍵盤至少更漂亮.只需從 droid 4+ 復制資源 - 您將在每個平臺上獲得漂亮的現代透明按鈕和透明布局.
UPD: I did not found solution. I implemented keyboard manually - big relative layout, common buttons and custom buttons and everything fine. By the way - custom keyboard at least more beautiful. Just copy resources from droid 4+ - and you'll get nice modern transparent buttons and transparent layout on every platform.
推薦答案
通常鍵盤只有在編輯時才可見,因此您可以通過對象捕獲編輯.如果它是一個 editText 框,那么您可以添加一個偵聽器,然后您可以禁用對編輯文本的任何響應.我不確定這是否對您有用,但至少您可以捕獲任何不需要的輸入.
Usually the keyboard is only visible if you are editing something, so you can trap the edits via the object. If its an editText box then you can add a listener and then you could disable any response to the edit text. I'm not sure if this is useful to you but at least you can trap any unwanted input.
// add a keylistener to keep track user input
editText.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// if keydown and "enter" is pressed
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
// do some thing or nothing
return true;
}
return false;
}
});
這篇關于在Android中禁用自定義鍵盤上的一鍵的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!