我有一个需要像iOS中的文本字段一样运行的edittext.当我点击它时,应该可以编辑,否则它应该被禁用.假设用户想要编辑某个值,当他按下后退按钮时,随着键盘关闭,我希望编辑文本被禁用以进行编辑.
我正在使用的是setCursorVisible(true)和setCursorVisible(false)方法.我确实尝试过使用keyCode事件,但他们没有帮助.这是我到目前为止尝试过的:
@Override
public void onBackPressed() {
// Had the InputMethodManager service here..
if(imm.isAcceptingText())
{
Toast.makeText(ProfileActivity.this,"working",Toast.LENGTH_SHORT).show();
}
else {
super.onBackPressed();
Toast.makeText(ProfileActivity.this,"back pressed called",Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
还尝试重写keyDown事件.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
//replaces the default 'Back' button action
if(keyCode==KeyEvent.KEYCODE_BACK)
{
Log.d("123","called,called");
return true;
}
return super.onKeyDown(keyCode, event);
}
Run Code Online (Sandbox Code Playgroud) android android-softkeyboard android-input-method android-edittext
我的应用在Android 4设备上崩溃了.当我在viewPager中滚动recyclerView时,为什么会出现此错误?
0805/? W/Binder: Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException
at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
08-16 10:58:44.238 926-10805/? W/System.err: java.lang.NullPointerException
08-16 10:58:44.244 926-10805/? W/System.err: at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
08-16 10:58:44.245 926-10805/? W/System.err: at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
08-16 10:58:44.245 926-10805/? W/System.err: at android.os.Binder.execTransact(Binder.java:404)
08-16 10:58:44.245 926-10805/? W/System.err: at dalvik.system.NativeStart.run(Native Method)
Run Code Online (Sandbox Code Playgroud) error-handling android runtimeexception android-input-method
我正在尝试InputMethodService从一个访问Activity,我遇到了权限问题.这适用于自定义键盘应用.
我想要实现的是将Activity后面创建的文本绑定到InputMethodService.在Activity从打开InputMethodService,然后从Activity我尝试启动Service(可能是这里的问题是我怎么打开.Activity从InputMethodService:
@Override public void onStartInputView(EditorInfo attribute, boolean restarting) {
super.onStartInputView(attribute, restarting);
Intent intent = new Intent(this, MyKeyboard.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
context.startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试与以下内容进行沟通InputMethodService的地方Activity:
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.xml.keyboard);
startService(new Intent(this, MyService.class));
}
Run Code Online (Sandbox Code Playgroud)
这是我的清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.package">
<application android:label="@string/ime_name">
<service android:name="MyService"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
<meta-data android:name="android.view.im" android:resource="@xml/method" />
</service>
<activity android:name=".MyKeyboard" android:theme="@style/Theme.Transparent"> …Run Code Online (Sandbox Code Playgroud) permissions service android android-input-method android-activity
我正在寻找这个问题的答案,但是从用户的角度来看.也就是说,如果平板电脑显示正常的应用程序UI,即使键盘在横向模式下可见,是什么导致手机不这样做?我讨厌这个"全屏"编辑框,而且更愿意看到该应用程序的正常用户界面的剩余一半(尽管可能会有更少的可见;对于今天的巨大手机,仍有"充足"的屏幕空间可用).
例如,是否有一个配置文件,其中一个可能调整一个设置(即让设备相信它的屏幕更大,或类似的效果)?我完全意识到这可能需要root,我对此很好.要清楚,我知道改变所有"冒犯"的应用程序既不可行也不可取.
我意识到这并不是一个严格意义上的编程问题,但是将短语组合在一起会非常困难,甚至可以得到一些合理的搜索结果.为了记录,我使用的是Nexus 4,但问题基本上与设备和版本无关.
使用Android软键盘输入文本并使用键盘下方的键手动关闭文本后,应用程序页面不会刷新.键盘存在的位置显示黑色空间.
我尝试了windowSoftInputMode的各种选项,但它并没有解决这个问题.可悲的是,adjustPan没有表现出预期的行为.当windowSoftInputMode设置为adjustPan时,键盘会隐藏文本字段.
隐藏软键盘后如何刷新页面以消除此问题?
我为Android制作了一个自定义键盘.当我按下我的键盘的退格键我使用
getCurrentInputConnection().deleteSurroundingText(1, 0);
Run Code Online (Sandbox Code Playgroud)
从输入字段中删除一个字母.但是当我选择一些文本然后按退格按钮时,不会删除所选文本.我应该使用什么方法输入连接,以便在按退格按钮时从键盘上删除所选文本?
android ime android-input-method custom-keyword inputconnection
我正在尝试为触摸事件的视图显示软输入键盘.这条线有效:
inputManager.toggleSoftInputFromWindow(getWindowToken(),0,0);
Run Code Online (Sandbox Code Playgroud)
但这条线不起作用:
inputManager.showSoftInput(this,0);
Run Code Online (Sandbox Code Playgroud)
为什么会这样?如果我想将软输入连接到视图怎么办?谢谢.
我在Mono for Android中的EditText控件遇到了一些非常奇怪的问题.我的解决方案是针对2.3而我正在调试T Mobile VivaCity.这是我的EditText的AXML
<EditText
android:inputType="text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ctl_searchText" />
Run Code Online (Sandbox Code Playgroud)
当我显示包含EditText的视图时,键盘会自动出现,这不是问题.问题是我无法通过点击键盘上的数字输入任何数字,唯一可以在文本字段中显示数字的方法是,如果我按住键并从上下文菜单中选择数字.虽然一旦我使用这种方法输入了一个数字,我就无法将其删除.我已经尝试了各种输入方法,并在SO中寻找类似的问题无济于事.这听起来像是设备的问题吗?或者是否有一些明显我在代码/ AXML中没有做的事情?
==编辑==
我认为我已经缩小了问题范围,它与EditText上使用的KeyPress事件处理程序有关.由于EditText表示搜索字段,我添加了属性android:singleLine ="true"以停止返回键添加额外的行,而是说"完成".当我向控件添加一个KeyPress事件处理程序时,这就是它阻止我输入数字,但没有处理程序它再次开始正常运行.这是我有的:
<EditText
android:id="@+id/ctl_searchText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
Run Code Online (Sandbox Code Playgroud)
EditText ctl_searchText = FindViewById<EditText>(Resource.Id.ctl_searchText);
ctl_searchText.KeyPress += (object sender, View.KeyEventArgs e) =>
{
if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
{
Toast.MakeText (this, ctl_searchText.Text, ToastLength.Short).Show ();
e.Handled = true;
}
};
Run Code Online (Sandbox Code Playgroud)
使用此代码,我无法在文本字段中输入数字,但我可以输入字母.当我删除事件处理程序时,它再次起作用,允许我输入所有字符.我要继续调查,这很奇怪.
android xamarin.android android-input-method android-edittext android-2.3-gingerbread
我想在Android中创建一个EditText,它有几行和数字输入.它用于输入矩阵.我已经有一个解决方案来android:inputType="textMultiLine",然后setRawInputType(Configuration.KEYBOARD_12KEY).但是,在水平方向编辑edittext时这不起作用,并且它也没有显示/我需要输入分数的斜杠().如果我将输入类型设置为setRawInputType(InputType.TYPE_CLASS_NUMBER),它也不能在水平方向上工作,并且总是在我输入空格后,它会切换到普通输入键盘.你知道任何有助于我的解决方案吗?
我需要根据语言的变化来更改键盘.
我做了一些研究,发现可以使用这些API完成
- InputMethodManager setInputMethod(android.os.IBinder,java.lang.String)
- InputMethodService switchInputMethod(java.lang.String)
对于第一个API,我需要一个IBinder令牌,可以通过调用从InputMethodService实例获取
mInputMethodService.getWindow().getWindow().的getAttributes().令牌
或者,如果我有对InputMethodService对象的引用,我可以简单地调用
mInputMethodService.switchInputMethod(ID)
更改输入法.
真正的问题是如何获得对InputMethodService对象的引用.
PS: 我不想使用InputMethodManager的showInputMethodPicker()因为我的要求我想从现有的具有语言列表的对话框中更改它.
我知道这对于用户应用程序是不可能的,但不确定它是否也不适用于系统应用程序.