为什么启动活动 - 重点是我的EditText,我不能删除它?

时间:2015-11-15 05:03:51

标签: android

我的应用程序上有很少的ui组件(button,EditText,ListView)。 当我启动我的应用程序时,焦点始终在EditText上作为默认值(即使我没有专注于此EditText控件) - 并且光标在此EditText控件上闪烁。

我可以使用'setCursorVisible'方法 - 但我认为没有任何理由这样做。

我如何让这个EditText只关注点击这个控制器?

我尝试定义'android:focusableInTouchMode =“true”',但这对我没有帮助。

1 个答案:

答案 0 :(得分:8)

添加android:focusable="true"& android:focusableInTouchMode="true"到您的布局的父元素(LinearLayout / RelativeLayout / FrameLayout / ..)。因为层次结构中的第一个可聚焦元素获得焦点,父元素将采用它,它应该解决您的问题。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/companyInputLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:errorTextAppearance="@style/error_appearance">

            <AutoCompleteTextView
                android:id="@+id/company"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prompt_company"
                android:inputType="text"/>

        </android.support.design.widget.TextInputLayout>

</LinearLayout>