【问题标题】:focus of EditText in android [duplicate]android中EditText的焦点[重复]
【发布时间】:2013-03-07 18:33:01
【问题描述】:

我的应用程序中有三个屏幕,每个屏幕有 3 个 editText。 我的问题是,当这些活动启动时,默认情况下光标会转到第一个编辑文本并且键盘会弹出。

我想要的是,当用户点击编辑框时,只会弹出键盘。

提前致谢,

苏迪尔

【问题讨论】:

标签: android android-edittext autofocus


【解决方案1】:

在您的 layout.xml 中,删除这一行(在 EditText 的底部):

 <requestFocus />

【讨论】:

    【解决方案2】:

    首先在您的 xml 文件中测试您的编辑文本中可能有这一行 &lt;requestFocus /&gt; 删除它,这里有一些可以帮助您的示例 Example link

    <EditText
       android:id="@+id/name"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       >
    
       <-- remove this line /// <requestFocus /> 
    </EditText>
    

    在你的活动中也添加这个

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

    【讨论】:

      【解决方案3】:

      最好的解决方案是:(在 Manifest 文件中)

          <activity android:name=".MainActivity" 
      
              android:windowSoftInputMode="stateHidden" />
      

      【讨论】:

        【解决方案4】:

        试试这个,在所有活动中添加windowSoftInputMode,它将避免键盘弹出。当你触摸EditText时,那个时间才会出现

         android:windowSoftInputMode="stateHidden|adjustPan"
        

        【讨论】:

          【解决方案5】:

          将此代码放入您的 oncreate() 方法中。

          @Override
              public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
          
              getWindow().setSoftInputMode(
                          WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
                  }
          

          【讨论】:

            猜你喜欢
            • 2021-05-03
            • 1970-01-01
            • 2013-06-04
            • 2021-03-25
            • 1970-01-01
            • 2015-01-10
            • 2017-12-23
            • 2016-09-21
            • 2012-09-25
            相关资源
            最近更新 更多