编辑文本的强制输入法 [英] Enforcing Input Method of Edit Text

查看:125
本文介绍了编辑文本的强制输入法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图寻找周围的答案,这一点,但我似乎无法找到答案。

I've tried searching around for an answer to this but I can't seem to find an answer.

是否有可能对我来说,prevent更改,我已经创建了一个EditText的输入法用户?目前,我有,我想只有类同手机键盘输入显示软键盘接受来自用户的数字一个EditText。通过在XML声明如下:

Is it possible for me to prevent a user from changing the input method of an edittext that I have created? Currently I have an edittext which I would like to only accept numbers from the user by displaying a soft keyboard similiar to the phone keypad input. By declaring the following in XML :

    <EditText 
    android:layout_height="wrap_content"    
    android:layout_width="fill_parent"    
    android:singleLine="true"     
    android:inputType="phone"
    android:numeric="decimal"       
    />

和还附加一个自定义DigitsKeyListener来,在getInputType方法返回InputType.TYPE_CLASS_PHONE的EditText上,我已成功取得了唯一的EditText接受小数以及使用软键盘,我想。

And also attaching a custom DigitsKeyListener to the edittext that returns InputType.TYPE_CLASS_PHONE in the getInputType method, I have succesfully made the edittext only accept decimal numbers as well as use the soft keyboard that I want.

的问题,如果用户不使用默认Android键盘但是开始。如果用户已经改变了他们的输入法自定义键盘或特定的语言环境,如日文输入法,所显示的软键盘变得缺乏对我的应用程序的目的。

The problem however starts if the user is not using the default Android Keyboard. If the user has changed their input method to a custom keyboard or to certain locales such as the Japanese IME, the soft keyboard that is shown becomes lacking for my application's purpose.

这可以通过长期持有上的EditText并选择不同的输入法,或改变它在另一个应用程序也会影响我的应用程序来实现。

This can be achieved by long holding on the edittext and selecting a different input method, or changing it in another application will also affect my application.

我的问题是,是否有任何可能的方式对我来说,prevent其他输入法在我的应用程序被使用?我希望我的应用程序始终使用默认的Andr​​oid键盘,而不是其他。

My question is, is there any possible way for me to prevent other Input Methods from being used in my application? I want my application to always use the default Android Keyboard, and nothing else.

推荐答案

据我所知,这是不可能强制用户使用特定的系统键盘的应用程序中(参考:的android应用特定的软键盘)。这本参考资料中向您展示如何创建自己的,虽然。它不会是非常难创建一个视图弹出当的EditText 的重点是,提供了一组数字的用户。

As far as I know, it's not possible to force a user to use a specific system keyboard inside your application (reference: android app specific soft keyboard). That reference does show you how to create your own, though. It wouldn't be terribly difficult to create a View that pops up when the EditText is focused that provides the user with a set of numbers.

您还可以设置安卓位数=0123456789属性,在的EditText 来禁止从其他字符被输入。

You can also set the android:digits="0123456789" attribute in your EditText to disallow other characters from being entered.

这篇关于编辑文本的强制输入法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆