How do you disable the SoftKeyboard key preview window?

强颜欢笑 提交于 2019-12-18 02:17:55

问题


When creating your own SoftKeyboard you are given a "key preview" by default.

How do you disable this?

Edit:

You can customise the keyPreview layout by changing the <KeyboardView> attribute android:keyPreviewLayout. This is styled by default to look at keyboard_key_preview.xml:

Edit 2: Following my be a red herring:

The source code suggests supplying 0 or not applying the tag android:keyPreviewLayout will result in no key preview appearing:

    ...
    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;
    }  

I've tried:

  • A styled KeyboardView with no keyPreviewLayout (Strangely though replacing this value changed the style of the preview.)
  • I made a keyPreviewLayout reference an id with a value of 0 (which causes a crash on inflation).

Stumped. :( Any help would be greatly appreciated!


回答1:


There's a method:

public void setPreviewEnabled(boolean previewEnabled)

But I don't know which version of the API that starts at.




回答2:


Have you tried this:

public static mEmptyView;

//somewhere where you have the context:
mEmptyView = new View(context);

@Override public View onCreateCandidatesView() {
    return mEmptyView;
}

This basically will always return an empty view, when the candidates should show up.




回答3:


Another way - add to xml
android:keyPreviewLayout="@null"

<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"
    />



回答4:


If you want to handle Preview for Particular Keys means handle it inside onPress Method.

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
    }
}


来源:https://stackoverflow.com/questions/7770099/how-do-you-disable-the-softkeyboard-key-preview-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!