- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图创建这个输入服务类:
package sandhiflowers.game.com;
import android.inputmethodservice.InputMethodService;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputConnection;
/**
* Created by vlado on 16.10.17.
*/
public class SandhiFlowersInputMethodService extends InputMethodService implements KeyboardView.OnKeyboardActionListener {
@Override
public View onCreateInputView() {
// get the KeyboardView and add our Keyboard layout to it
KeyboardView keyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard_view, null);
Keyboard keyboard = new Keyboard(this, R.xml.number_pad);
keyboardView.setKeyboard(keyboard);
keyboardView.setOnKeyboardActionListener(this);
return keyboardView;
}
@Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
if (ic == null) {
return;
}
switch (primaryCode) {
case Keyboard.KEYCODE_DELETE:
CharSequence selectedText = ic.getSelectedText(0);
if (TextUtils.isEmpty(selectedText)) {
// no selection, so delete previous character
ic.deleteSurroundingText(1, 0);
} else {
// delete the selection
ic.commitText("", 1);
}
ic.deleteSurroundingText(1, 0);
break;
default:
char code = (char) primaryCode;
ic.commitText(String.valueOf(code), 1);
}
}
@Override
public void onPress(int primaryCode) { }
@Override
public void onRelease(int primaryCode) { }
@Override
public void onText(CharSequence text) { }
@Override
public void swipeLeft() { }
@Override
public void swipeRight() { }
@Override
public void swipeDown() { }
@Override
public void swipeUp() { }
}
我得到了这个类强制转换异常:
10-29 17:41:49.133 7804-7804/sandhiflowers.game.com E/AndroidRuntime: FATAL EXCEPTION: main
Process: sandhiflowers.game.com, PID: 7804
java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.inputmethodservice.KeyboardView
at sandhiflowers.game.com.SandhiFlowersInputMethodService.onCreateInputView(SandhiFlowersInputMethodService.java:19)
at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1135)
at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:1498)
at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:1473)
at android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:452)
at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:203)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
这是导致错误的行:
KeyboardView keyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard_view, null);
还有这个:
10-29 18:46:50.997 18888-18888/? I/art: Late-enabling -Xcheck:jni
10-29 18:46:51.033 18888-18888/? W/Environment: userEnvironment:hasSdcard:true,isswitch:true
10-29 18:46:51.100 18888-18888/sandhiflowers.game.com D/ActivityThread: hoder:android.app.IActivityManager$ContentProviderHolder@dd6e5e4,provider,holder.Provider:android.content.ContentProviderProxy@10e38a4d
10-29 18:46:51.115 18888-18888/sandhiflowers.game.com D/Proxy: setHttpRequestCheckHandler
10-29 18:46:51.650 18888-18888/sandhiflowers.game.com D/ActivityThread: installProvider: context.getPackageName()=sandhiflowers.game.com
10-29 18:46:51.660 18888-18888/sandhiflowers.game.com I/InstantRun: starting instant run server: is main process
10-29 18:46:51.670 18888-18888/sandhiflowers.game.com D/ActivityThread: BIND_APPLICATION handled : 0 / AppBindData{appInfo=ApplicationInfo{390e7c50 sandhiflowers.game.com}}
10-29 18:46:51.750 18888-18888/sandhiflowers.game.com D/ActivityThread: SVC-Creating service: CreateServiceData{token=android.os.BinderProxy@2aeb7e49 className=sandhiflowers.game.com.SandhiFlowersInputMethodService packageName=sandhiflowers.game.com intent=null}
10-29 18:46:51.754 18888-18888/sandhiflowers.game.com D/FeatureProxyBase: FeatureProxyBase class constructor
10-29 18:46:51.755 18888-18888/sandhiflowers.game.com D/MultiWindow: MultiWindowProxy constructor.
10-29 18:46:51.755 18888-18888/sandhiflowers.game.com D/FeatureProxyBase: getService(), serviceName = multiwindow_service_v1
10-29 18:46:51.756 18888-18888/sandhiflowers.game.com D/FeatureProxyBase: FeatureProxyBase class constructor
10-29 18:46:51.756 18888-18888/sandhiflowers.game.com D/MultiWindow: MultiWindowProxy constructor.
10-29 18:46:51.756 18888-18888/sandhiflowers.game.com D/FeatureProxyBase: getService(), serviceName = multiwindow_service_v1
10-29 18:46:51.773 18888-18888/sandhiflowers.game.com D/AccessibilityManager: setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false, mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false
java.lang.Throwable: setStateLocked
at android.view.accessibility.AccessibilityManager.setStateLocked(AccessibilityManager.java:553)
at android.view.accessibility.AccessibilityManager.tryConnectToServiceLocked(AccessibilityManager.java:636)
at android.view.accessibility.AccessibilityManager.<init>(AccessibilityManager.java:226)
at android.view.accessibility.AccessibilityManager.getInstance(AccessibilityManager.java:206)
at android.view.View.setFlags(View.java:9843)
at android.view.ViewGroup.initViewGroup(ViewGroup.java:536)
at android.view.ViewGroup.<init>(ViewGroup.java:525)
at android.widget.LinearLayout.<init>(LinearLayout.java:215)
at android.widget.LinearLayout.<init>(LinearLayout.java:211)
at android.widget.LinearLayout.<init>(LinearLayout.java:206)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.inputmethodservice.InputMethodService.initViews(InputMethodService.java:731)
at android.inputmethodservice.InputMethodService.onCreate(InputMethodService.java:703)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2982)
at android.app.ActivityThread.access$1800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1553)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
10-29 18:46:51.801 18888-18888/sandhiflowers.game.com V/SettingsInterface: invalidate [global]: current 2 != cached 0
10-29 18:46:51.802 18888-18888/sandhiflowers.game.com D/ActivityThread: SVC-CREATE_SERVICE handled : 0 / CreateServiceData{token=android.os.BinderProxy@2aeb7e49 className=sandhiflowers.game.com.SandhiFlowersInputMethodService packageName=sandhiflowers.game.com intent=null}
10-29 18:46:51.807 18888-18888/sandhiflowers.game.com D/ActivityThread: SVC-BIND_SERVICE handled : 0 / BindServiceData{token=android.os.BinderProxy@2aeb7e49 intent=Intent { act=android.view.InputMethod cmp=sandhiflowers.game.com/.SandhiFlowersInputMethodService }}
还有这个:
10-29 18:57:54.264 26752-26752/sandhiflowers.game.com E/AndroidRuntime: FATAL EXCEPTION: main
Process: sandhiflowers.game.com, PID: 26752
android.view.InflateException: Binary XML file line #2: Error inflating class com.game.sandhiflowers.SandhiFlowersSoftKeyboard
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at sandhiflowers.game.com.SandhiFlowersInputMethodService.onCreateInputView(SandhiFlowersInputMethodService.java:19)
at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1135)
at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:1498)
at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:1473)
at android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:452)
at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:203)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.game.sandhiflowers.SandhiFlowersSoftKeyboard" on path: DexPathList[[zip file "/data/app/sandhiflowers.game.com-1/base.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_dependencies_apk.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_slice_0_apk.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_slice_1_apk.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_slice_2_apk.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_slice_3_apk.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_slice_4_apk.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_slice_5_apk.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_slice_6_apk.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_slice_7_apk.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_slice_8_apk.apk", zip file "/data/app/sandhiflowers.game.com-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:571)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at sandhiflowers.game.com.SandhiFlowersInputMethodService.onCreateInputView(SandhiFlowersInputMethodService.java:19)
at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1135)
at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:1498)
at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:1473)
at android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:452)
at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:203)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Suppressed: java.lang.ClassNotFoundException: com.game.sandhiflowers.SandhiFlowersSoftKeyboard
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 20 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
我很惊讶我在编码时没有在 Android Studio 中遇到任何编译错误。
将 LinearLayout 转换为 KeyboardView 的正确方法是什么?或者我应该使用其他类?
注意:我使用的是 Android Studio 2.3 和 Android 5.1
最佳答案
我猜,R.layout.keyboard_view
的父 View 应该是 KeyboardView
,而不是 LinearLayout
。变化:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
到:
<your.packages.KeyboardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</your.packages.KeyboardView>
关于java - 将 LinearLayout 转换到 KeyboardView 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47003027/
我有课 public class OwnKeyboardView extends KeyboardView { ... } 它有重写方法OnDraw: @Override public voi
如何禁用 swipeLeft()/swipeRight() 方法,因为它拦截 onRelease() 方法然后我快速移动手指? 最佳答案 我找到了解决方案:我需要在 swipeLeft() 中调用 o
我最近遇到了 Android 键盘 View 的问题。 我想要实现的是一个像样的键盘,我可以在其中添加以像素为单位的键间距,其余空间将由键共享,具体取决于我对它们的加权方式。 我还发现百分比宽度不准确
我的应用程序有一个自定义键盘,但我似乎无法在设备旋转时调整它的大小。你可以在这里明白我的意思:http://imgur.com/TsEM9在这里:http://imgur.com/2hhX8 在我的
我为我的应用程序制作了一个自定义键盘,我想更改该键的文本大小。 有什么办法可以存档吗?可能正在使用主题或任何其他方式? 最佳答案 没关系。我找到了 KeyboardView 属性:android:ke
我试图通过应用主题来更改 KeyboardView 的默认样式,但没有成功。我的目标 SDK 是 1.6 和 Xperia X10。有人可以帮忙吗? /res/vaules/style.xml:
我有自定义的 MyKBV 类,它扩展了 KeyBoardView。我创建了这个自定义 View 来为键使用自定义字体。我能够在键上看到更改的字体,但问题是每个键都与 XML 中的默认键重叠,我认为它是
KeyboardView android 团队在 API 级别 29 中已正式弃用,我无法找到替代方法。请让我知道是否有任何替代方案? 最佳答案 Google 建议的唯一解决方案是复制 Keyboar
我定义了一个像这样的自定义KeyboardView: public class MyKeyboardView extends KeyboardView { public
您好,我实现了一个在 ListView 中显示结果的 SearchView。我面临的问题是我有一个自定义键盘,而我的 Listview 与 keyboardView 重叠,因此我无法按下键盘上的某些键
我正在为 android 开发 IME。我可以选择为键盘设置主题。当我第二次尝试给 keyboardView 充气时出现的问题是它不起作用 KeyboardView k = (KeyboardView
我一直在尝试寻找一种方法来在按下 KeyboardView 键时实现波纹效果。听起来很简单,但我已经尝试了所有添加适用于其他类型 View ( ListView 、按钮等)的波纹的方法,但都没有成功。
我正在尝试制作自定义键盘,但它没有输出我在 Key 节点上的 keyOutputText 中设置的文本值。 这是activity_main.xml: 这是键盘布局:
我试图创建这个输入服务类: package sandhiflowers.game.com; import android.inputmethodservice.InputMethodService;
有没有办法在 Android 的 KeyboardView 中有一个带有一些图片的 GridLayout?我试图用 xml 编写它,但它给了我错误,我不能在 KeyboardView 中包含该元素。
我有一排 key 。每个键的宽度为 18.5%,间隙为 2%。但是,我希望第一个键的间隙为 10%,最后一个键的间隙为 右侧的 10%。在每个键上设置 horizontalGap 来实现这种效果很
这个问题在这里已经有了答案: How to change background color of key for android soft keyboard? (2 个答案) How to chan
根据 KeyboardView.OnKeyboardActionListener.onRelease() SDK 文档,“对于重复的键,只调用一次”。但是,如果我使用 Android Softkeyb
我正在尝试为我的 KeyboardView 设置自定义背景。设置 XML 属性 keyBackground似乎是解决它的方法,但是当它试图膨胀可绘制对象时,我的 logcat 中不断出现 NullPo
我正在尝试在运行时动态更改键盘键背景。但是可绘制状态列表在 KeyboardView 类的 onDraw 方法中不起作用。我写的代码是 - @Override public void onDraw(@
我是一名优秀的程序员,十分优秀!