windowSoftInputMode =“adjustResize”导致自定义键盘布局出现问题

时间:2015-11-30 20:23:08

标签: android keyboard custom-keyboard

我正在开发一个自定义键盘,并希望在键盘上方添加TextView以显示用户已输入的内容或他想要输入的字词的建议。

要做到这一点,我有以下布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <android.inputmethodservice.KeyboardView
        android:id="@+id/keyboard"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:keyPreviewLayout="@layout/preview"
        android:keyBackground="@drawable/key_background"
        android:background="@color/color_primary"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/keyboard"
        android:padding="8dp"
        android:gravity="center"
        android:background="@color/color_primary_dark"
        android:textColor="@android:color/white"
        android:text="some sample text"
        />
</RelativeLayout>

以及InputMethodService上的以下代码:

public class FancyInputMethodService extends InputMethodService {
    @Override
    public View onCreateInputView() {
        final RelativeLayout layout = (RelativeLayout) getLayoutInflater().inflate(R.layout.keyboard_layout, null);
        final KeyboardView keyboardView = (KeyboardView) layout.findViewById(R.id.keyboard);
        final Keyboard keyboard = new Keyboard(this, R.xml.qwerty);
        keyboardView.setKeyboard(keyboard);
        return layout;
    }
}

在屏幕顶部的正常EditText处,键盘看起来很好并且效果很好:

enter image description here

但如果EditText位于使用清单中的标记Activity的{​​{1}}中,则键盘视图似乎覆盖实际视图而不是透明。

enter image description here

左图显示软键盘关闭时的实际视图,中间的图像显示键盘打开时的奇怪行为,右侧的图像显示默认键盘,表现出我期望的行为。

我已经尝试将布局背景设置为透明,但这没有帮助。

问题出现在多个应用中,例如WhatsApp,Hangouts,Facebook等......我错过了什么或者出了什么问题?

1 个答案:

答案 0 :(得分:0)

tl; dr

您没有按预期使用InputMethodService,而是使用CandidateView框架。

完整答案:

  1. 您的键盘布局不应包含文字建议。

  2. 覆盖InputMethodService#onCreateCandidatesView。它应该是这样的:

  3. public View onCreateCandidatesView(){

        mYourView = getLayoutInflater().inflate(R.layout.your_view, null);
        return mYourView;
    }
    

    3。当您想要显示/隐藏候选视图时,请使用setCandidatesViewShown(boolean show)

相关问题