我在Android中有一个活动,包含两个元素:

编辑文本列表视图

当“活动”启动时,EditText立即具有输入焦点(闪烁光标)。我不希望任何控件在启动时具有输入焦点。我尝试了:

EditText.setSelected(false);
EditText.setFocusable(false);

没有运气。如何说服EditText在“活动”启动时不选择自己?


当前回答

在Manifest.xml文件的活动标记中添加android:windowSoftInputMode=“stateAlwaysHidden”。

来源

其他回答

您可以通过使用请求焦点并使用键盘隐藏代码来指定其他小部件的焦点。

View current = getCurrentFocus();

if (current != null) 
    current.clearFocus();

ListView中的EditText无法正常工作。使用EditText时,最好将TableLayout与自动生成的行一起使用。

<TextView
    android:id="@+id/textView01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:focusable="true"
    android:focusableInTouchMode="true"
    style="@android:style/Widget.EditText"/>

简单的解决方案:在活动标签中的AndroidManifest中使用

android:windowSoftInputMode="stateAlwaysHidden"