![](/img/trans.png)
[英]How to disable key preview in popup keyboard (not in main softkeyboard layout)?
[英]How do you disable the SoftKeyboard key preview window?
創建自己的SoftKeyboard時,默認情況下會給出“鍵預覽”。
你怎么禁用這個?
編輯:
您可以通過更改<KeyboardView>
屬性android:keyPreviewLayout
來自定義keyPreview
布局。 默認情況下,它會設置為查看keyboard_key_preview.xml :
編輯2: 跟隨我成為紅鯡魚:
源代碼建議提供0或不應用標簽android:keyPreviewLayout
將導致沒有出現鍵預覽:
...
case com.android.internal.R.styleable.KeyboardView_keyPreviewLayout:
previewLayout = a.getResourceId(attr, 0);
break;
...
if (previewLayout != 0) {
mPreviewText = (TextView) inflate.inflate(previewLayout, null);
mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
mPreviewPopup.setContentView(mPreviewText);
mPreviewPopup.setBackgroundDrawable(null);
} else {
mShowPreview = false;
}
我試過了:
keyPreviewLayout
引用了一個值為0的id(導致通脹崩潰)。 難住了。 :( 任何幫助將不勝感激!
有一種方法:
public void setPreviewEnabled(boolean previewEnabled)
但我不知道從哪個版本的API開始。
另一種方法 - 添加到xml
機器人:keyPreviewLayout = “@空”
<android.inputmethodservice.KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:keyPreviewLayout="@null"
android:visibility="gone"
/>
如果要處理預覽特定鍵,則意味着在onPress方法中處理它。
override fun onPress(primaryCode: Int) {
handleKeyPreviews(primaryCode)
}
private fun handleKeyPreviews(code: Int) {
when (code) {
Keyboard.KEYCODE_DELETE, Keyboard.KEYCODE_SHIFT, Keyboard.KEYCODE_DONE, 32 ->
keyboardView?.isPreviewEnabled = false
else ->
keyboardView?.isPreviewEnabled = true
}
}
你試過這個:
public static mEmptyView;
//somewhere where you have the context:
mEmptyView = new View(context);
@Override public View onCreateCandidatesView() {
return mEmptyView;
}
當候選人出現時,這基本上總會返回一個空視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.