【问题标题】:EditText doesn't start automaticallyEditText 不会自动启动
【发布时间】:2012-08-03 01:40:41
【问题描述】:

在我的应用程序中,我有一个 EditText。如何让它不自动启动?比如:一旦他们打开活动,它会自动将鼠标设置为EditText,然后键盘就会打开,所以他们可以输入......

当他们点击它时,我是否可以打开它(键盘显示并且用户可以输入)?

【问题讨论】:

标签: android keyboard android-edittext


【解决方案1】:

好的,所以根据您的问题,我发现您的 EditText 在开始活动时得到了关注。您可以使用以下命令禁用焦点以抑制键盘。

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

访问此Close/hide the Android Soft Keyboard

【讨论】:

    【解决方案2】:

    路西法的答案必须有效。但是当我遇到同样的问题时,那个解决方案不起作用,有人建议我这样做。

    添加一个假布局作为父布局中的第一个元素并使其具有焦点。

    像这样:

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

    这绝对有效,但最好的解决方案是:

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    

    【讨论】:

      猜你喜欢
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      相关资源
      最近更新 更多