安卓。 Activity 启动时自动聚焦 TextView

标签 android focus android-edittext

我有一个 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/

相关文章:

android - 电池和网络未显示的最上面的栏

Android TextView 兼容自动调整大小,只缩小字体大小?

android - Edittext imeOptions actionDone 不使用数字属性?

javascript - 如何知道焦点何时在 react native textInput 中丢失?

wpf - 专注于 Canvas 中的边框

android - EditText 获得焦点后不会失去焦点

android - 如何root Genymotion 安卓模拟器?

internet-explorer - Iframe、pdf 和焦点与 Internet Explorer

Android 使用形状、选择器或列表针对不同状态的不同 EditText 背景