我正在尝试实现(又一个!)输入法。我从软键盘示例开始,它实现了 KeyboardView 对象的使用和扩展,它扩展了 View。我想以完全不同的方式扩展 View,所以我将以下内容放在我的 input.xml 中。请注意,我的目标是为 UI 提供一个透明的表面。
<?xml version="1.0" encoding="utf-8"?>
<com.diffstrokes.ime.StrokeView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:cacheColorHint="@null" >
</com.diffstrokes.ime.StrokeView>
调用 IME 的活动被浅灰色背景遮挡。例如,如果我将背景颜色更改为半透明的红色,我会在视图背景上方看到几行灰色像素。这个背景来自哪里,我该如何摆脱它?
我尝试使用 LinearLayout 而不是视图。LinearLayout 包含两个 View 标签。在我的 onCreateInputView() 函数中,我使用以下内容为 LinearLayout 充气:
LinearLayout llo =
(LinearLayout) getLayoutInflater().inflate(
R.layout.dslayout, null);
完成没有问题,onCreateInputView()
但在某些时候我得到一个异常,如以下日志所示:
06-12 15:17:01.350: E/AndroidRuntime(14002): FATAL EXCEPTION: main
06-12 15:17:01.350: E/AndroidRuntime(14002):
java.lang.IllegalStateException: The specified child already has a
parent. You must call removeView() on the child's parent first. 06-12
15:17:01.350: E/AndroidRuntime(14002): at
android.view.ViewGroup.addViewInner(ViewGroup.java:2117) 06-12
15:17:01.350: E/AndroidRuntime(14002): at
android.view.ViewGroup.addView(ViewGroup.java:2012) 06-12
15:17:01.350: E/AndroidRuntime(14002): at
android.view.ViewGroup.addView(ViewGroup.java:1992) 06-12
15:17:01.350: E/AndroidRuntime(14002): at
android.inputmethodservice.InputMethodService.setInputView(InputMethodService.java:1105)
06-12 15:17:01.350: E/AndroidRuntime(14002): at
android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:963)
06-12 15:17:01.350: E/AndroidRuntime(14002): at
android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:1318)
06-12 15:17:01.350: E/AndroidRuntime(14002): at
android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:1293)
06-12 15:17:01.350: E/AndroidRuntime(14002): at
android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:392)
06-12 15:17:01.350: E/AndroidRuntime(14002): at
android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:176)
06-12 15:17:01.350: E/AndroidRuntime(14002): at
com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
06-12 15:17:01.350: E/AndroidRuntime(14002): at
android.os.Handler.dispatchMessage(Handler.java:99) 06-12
15:17:01.350: E/AndroidRuntime(14002): at
android.os.Looper.loop(Looper.java:130) 06-12 15:17:01.350:
E/AndroidRuntime(14002): at
android.app.ActivityThread.main(ActivityThread.java:3806) 06-12
15:17:01.350: E/AndroidRuntime(14002): at
java.lang.reflect.Method.invokeNative(Native Method) 06-12
15:17:01.350: E/AndroidRuntime(14002): at
java.lang.reflect.Method.invoke(Method.java:507) 06-12 15:17:01.350:
E/AndroidRuntime(14002): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-12 15:17:01.350: E/AndroidRuntime(14002): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-12
15:17:01.350: E/AndroidRuntime(14002): at
dalvik.system.NativeStart.main(Native Method)
当我膨胀视图时,这不会发生。谁能解释为什么?