我正在开发一个自定义键盘,并且想要在键盘上添加一个TextView
以显示用户已输入的内容或他想要输入的单词的建议。windowSoftInputMode =“adjustResize”导致自定义键盘布局出现问题
为了做到这一点,我有以下布局:
<?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
在屏幕上方的键盘看起来很好,效果很好:
但是,如果EditText
在Activity
中使用清单中的标志android:windowSoftInputMode="adjustResize"
,则键盘视图似乎覆盖实际视图而不是透明。
左边的图像显示了软键盘的实际视图关闭时,中间的图像显示了怪异的行为,当键盘打开,右边的图像显示了默认的键盘行为我会期待。
我已经尝试将布局背景设置为透明,但这并没有帮助。
该问题出现在多个应用程序中,例如, WhatsApp的,环聊,Facebook等...我错过了什么或错在哪里?