【android】禁止EditText自动获取焦点

有时候在页面加载的时候,我们需要默认EditText不自动获取焦点,以防止自动弹出输入法解决方法如下:在EditText的父布局中加入以下属性:android:focusable="true

by
江江
on
2017/07/12

有时候在页面加载的时候,我们需要默认EditText不自动获取焦点,以防止自动弹出输入法

解决方法如下:

在EditText的父布局中加入以下属性:

android:focusable="true"
android:focusableInTouchMode="true"

示例:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:focusable="true"
    android:focusableInTouchMode="true">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
江江江江于 2026-10-15 05:39:46 修改阅读 1347评论 0点赞 0