我有一个 Activity ,其中的 View 有几个 EditText 组件。
当 Activity 开始时,第一个 EditTexts 获得焦点并出现键盘。我想避免这个“功能”(我的意思是我希望 Activity 开始后不会有弹出键盘)
最佳答案
创建一个 LinearLayout(我不知道其他类型的布局是否可行)。设置属性 android:focusable="true"
和 android:focusableInTouchMode="true"
。
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
android:focusable="true" android:focusableInTouchMode="true"
android:layout_width="0px" android:layout_height="0px"/>
<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="@+id/text"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:nextFocusUp="@+id/text" android:nextFocusLeft="@+id/text"/>
关于安卓。 Activity 启动时自动聚焦 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4671915/