简体   繁体   English

聚焦EditText时如何隐藏IME

[英]How to hide IME when EditText is focused

I want EditText not to extend IME when it is focused on Android Wear. 我希望EditText在专注于Android Wear时不扩展IME。 I read and implemented in the same way as the following thread: Prevent EditText from automatically focusing 我以与以下线程相同的方式阅读和实现: 防止EditText自动聚焦

However, IME appears. 但是,IME出现。 Is it impossible to hide IME for an EditText on Android Wear? 是否可以在Android Wear上为EditText隐藏IME?

I tried 3 methods: 我尝试了3种方法:

  1. Added the following code in the onCreate() method: 在onCreate()方法中添加了以下代码:

     {getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);} 
  2. Added the following code in the activity tag in AndroidManifest.xml 在AndroidManifest.xml的活动标记中添加了以下代码

     android:windowSoftInputMode="stateAlwaysHidden" 
  3. Added the following code in rect_activity_main.xml 在rect_activity_main.xml中添加了以下代码

     <LinearLayout android:layout_width="0dp" android:layout_height="0dp" android:background="@android:color/transparent" android:focusable="true" android:focusableInTouchMode="true"/> 

None of them worked. 他们都没有工作。

Best regards, gellpro 最好的问候,gellpro

Check Show the Input Method On Demand . 选中显示按需输入法 It's noted that the system hides the input method when the user finishes the task in the test field or the user can hide it with a system control. 请注意,当用户在测试字段中完成任务时,系统将隐藏输入法,或者用户可以使用系统控件将其隐藏。 With this, try to specify how your UI should respond . 以此尝试尝试指定UI的响应方式 It's mentioned that, 提到了

To declare your preferred treatment in an activity, use the android:windowSoftInputMode attribute in your manifest's element with one of the "adjust" values. 要在活动中声明您的首选处理方式,请在清单元素中使用android:windowSoftInputMode属性以及“ adjust”值之一。

Then, to implement hiding IME, try using InputMethodManager with constant set to RESULT_UNCHANGED_HIDDEN . 然后,要实现隐藏的IME,请尝试使用常数设置为RESULT_UNCHANGED_HIDDEN InputMethodManager This will flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver) : the state of the soft input window was unchanged and remains hidden. 这将标记来自showSoftInput(View, int, ResultReceiver)hideSoftInputFromWindow(IBinder, int, ResultReceiver)ResultReceiver结果代码:软输入窗口的状态未更改,并保持隐藏状态。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM