在Android中强制键盘到英语

时间:2015-10-12 13:37:53

标签: android android-softkeyboard

如何强制键盘只显示英语(英国)。我需要这个,因为我想阻止用户输入其他语言,如阿拉伯语,中文等。如果用户使用阿拉伯语键盘,那么我需要强制我的应用程序(键盘)使用英语(英国)键盘。

请帮助我实现这一目标。提前谢谢。

2 个答案:

答案 0 :(得分:4)

我认为过滤输入键会更好。 即使您能够强制使用英语键盘也不会强迫用户只使用英文字母,因为他们也可以长按字符,甚至可以使用其他硬件键盘(非英语)。

所以,你应该听一些onTextChanged using UnityEngine; using System.Collections; using System.Collections.Generic; using System; using System.Threading; using System.Linq; public class Loom : MonoBehaviour { public static int maxThreads = 8; static int numThreads; private static Loom _current; private int _count; public static Loom Current { get { Initialize(); return _current; } } void Awake() { _current = this; initialized = true; } static bool initialized; static void UnhandledHandler(object sender, UnhandledExceptionEventArgs args) { Exception e = (Exception) args.ExceptionObject; Debug.Log("MyHandler caught : " + e.Message); Debug.Log("Runtime terminating: {0}" + args.IsTerminating); } static void Initialize() { if (!initialized) { if(!Application.isPlaying) return; initialized = true; var g = new GameObject("Loom"); _current = g.AddComponent<Loom>(); } } private List<Action> _actions = new List<Action>(); public struct DelayedQueueItem { public float time; public Action action; } private List<DelayedQueueItem> _delayed = new List<DelayedQueueItem>(); List<DelayedQueueItem> _currentDelayed = new List<DelayedQueueItem>(); public static void QueueOnMainThread(Action action) { QueueOnMainThread( action, 0f); } public static void QueueOnMainThread(Action action, float time) { if(time != 0) { lock(Current._delayed) { Current._delayed.Add(new DelayedQueueItem { time = Time.time + time, action = action}); } } else { lock (Current._actions) { Current._actions.Add(action); } } } public static Thread RunAsync(Action a) { Initialize(); while(numThreads >= maxThreads) { Thread.Sleep(1); } Interlocked.Increment(ref numThreads); ThreadPool.QueueUserWorkItem(RunAction, a); return null; } private static void RunAction(object action) { try { ((Action)action)(); } catch { } finally { Interlocked.Decrement(ref numThreads); } } void OnDisable() { if (_current == this) { _current = null; } } // Use this for initialization void Start() { } List<Action> _currentActions = new List<Action>(); // Update is called once per frame void Update() { lock (_actions) { _currentActions.Clear(); _currentActions.AddRange(_actions); _actions.Clear(); } foreach(var a in _currentActions) { a(); } lock(_delayed) { _currentDelayed.Clear(); _currentDelayed.AddRange(_delayed.Where(d=>d.time <= Time.time)); foreach(var item in _currentDelayed) _delayed.Remove(item); } foreach(var delayed in _currentDelayed) { delayed.action(); } } } 作为例子并拒绝你不想接受的所有字符。

答案 1 :(得分:1)

你永远不应该强迫用户做那种事情。如果您检测到非英语键盘,只需弹出一个要求他们使用英语键盘的弹出键盘,然后给他们这样做的步骤! 正如托马斯所说,如果你确定这样做,你就应该得到答案