【问题标题】:How to hide IME when EditText is focused当 EditText 获得焦点时如何隐藏 IME
【发布时间】:2018-02-10 01:14:25
【问题描述】:

我希望EditText 在专注于 Android Wear 时不要扩展 IME。 我以与以下线程相同的方式阅读和实现: Prevent EditText from automatically focusing

但是,会出现 IME。 在 Android Wear 上是否无法隐藏 EditText 的 IME?

我尝试了 3 种方法:

  1. 在 onCreate() 方法中添加如下代码:

    {getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);}
    
  2. 在AndroidManifest.xml的activity标签中添加如下代码

    android:windowSoftInputMode="stateAlwaysHidden"
    
  3. 在rect_activity_main.xml中添加如下代码

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

它们都不起作用。

最好的问候,gellpro

【问题讨论】:

标签: java android wear-os ime


【解决方案1】:

检查Show the Input Method On Demand。需要注意的是,当用户完成测试字段中的任务时,系统会隐藏输入法,或者用户可以通过系统控件将其隐藏。有了这个,尝试specify how your UI should respond。据说,

要在活动中声明您的首选处理方式,请使用清单元素中的 android:windowSoftInputMode 属性和“调整”值之一。

然后,要实现隐藏 IME,请尝试使用 InputMethodManager 并将常量设置为 RESULT_UNCHANGED_HIDDEN。这将标记来自showSoftInput(View, int, ResultReceiver) 和hideSoftInputFromWindow(IBinder, int, ResultReceiver) 的ResultReceiver 结果代码:软输入窗口的状态未更改并保持隐藏状态。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2016-05-20
    • 1970-01-01
    • 2022-11-21
    • 2022-12-31
    • 1970-01-01
    • 2021-02-13
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多