android - 禁用对编辑文本的自动对焦

标签 android android-layout android-edittext autofocus

我有一个编辑文本:

   <LinearLayout android:id="@+id/linearLayout7" android:layout_width="match_parent" android:layout_height="wrap_content">
        <EditText android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1" android:id="@+id/editText1" android:text="3">
            <requestFocus></requestFocus>
        </EditText>
        <Button android:text="Button" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button2"></Button>
    </LinearLayout>

然后是下面的一些其他东西

我遇到的问题是,当应用程序启动时,焦点在输入上,我不希望在应用程序启动时焦点在输入上。

我尝试删除

<requestFocus></requestFocus>

事情,它什么也没做。

最佳答案

添加 android:focusable="true"android:focusableInTouchMode="true" EditText 的父布局中的元素如下;

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout7" android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:focusable="true" android:focusableInTouchMode="true">

我想,它应该对你有帮助。

另见;
Android Developers official guide on handling touch and input

关于android - 禁用对编辑文本的自动对焦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7593887/

相关文章:

android - Android 设备上的最大 dp/dip

java - 在 Android 上使用 Flutter 显示在其他应用程序之上

java - 创建自定义 Android View /小部件

android - 如何正确扩展布局类?

android-layout - 硬编码字符串 “Button” ,应使用@string 资源

Android:使用 XML 自定义 EditText 布局

android - 使用 ACTION_CAPTIVE_PORTAL_SIGN_IN

java - 使用 appcompat v7 更改 EditText 底线颜色

java - 在 HTC 长按上使用 TextWatcher 计算字符失败

android - 使用 Kotlin 登录 Twitter