Android 如何在页面加载时从TextInputLayout中移除焦点?

Android 如何在页面加载时从TextInputLayout中移除焦点?,android,Android,当这个xml加载到一个片段中时,焦点直接转到第二个编辑文本,我希望编辑文本应该关注触摸它。我想用我自己的颜色来暗示和显示我在上面键入的文字。非常感谢您的帮助 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://sc

当这个xml加载到一个片段中时,焦点直接转到第二个编辑文本,我希望编辑文本应该关注触摸它。我想用我自己的颜色来暗示和显示我在上面键入的文字。非常感谢您的帮助

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="23dp">

    <TextView
        android:id="@+id/basic_details_heading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/basic_details"
        android:textSize="16sp"
        android:paddingLeft="0dp"
        android:textColor="@color/basic_details_gray"
        android:textStyle="normal"
        android:typeface="monospace"
        android:includeFontPadding="false"
        android:layout_alignParentLeft="true"
        />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/container_first"
        android:layout_below="@+id/basic_details_heading"
        android:paddingLeft="0dp"
        >

      <!--  <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/profile_created_for"
            android:id="@+id/sub_head_one"
            android:textStyle="normal"
            android:textColor="@color/login_background"
            android:textSize="12sp"
            android:paddingLeft="0dp"
            android:paddingTop="0dp"
            android:visibility="gone"
            android:includeFontPadding="false"
            android:layout_alignParentLeft="true"
            />-->
        <android.support.design.widget.TextInputLayout
            android:id="@+id/profile_created_for"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >

            <EditText
                android:id="@+id/edit_text_profile_created_for"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="-4dp"
                android:textSize="15sp"
                android:textColor="@color/black"
                android:textStyle="normal"
                android:hint="Profile Created For"
                android:focusable="false"/>

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

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/nav_next"
            android:layout_alignParentRight="true"
            android:paddingTop="20dp"
            android:id="@+id/profile_created_for_arrow"
            />


        <android.support.design.widget.TextInputLayout
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_created_for"
            android:focusableInTouchMode="true"
            >

            <EditText
                android:id="@+id/edit_text_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="-4dp"
                android:textSize="15sp"
                android:textColor="@color/black"
                android:textStyle="normal"
                android:hint="Name"
                />

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


</RelativeLayout>


</RelativeLayout>

尝试以下操作:在xml中文本布局之前添加一个虚拟对象,这样它就可以使用焦点

<LinearLayout
android:focusable="true" 
android:focusableInTouchMode="true"
android:layout_width="0px" 
android:layout_height="0px"/>

在根视图(TextInputLayout)中使用此属性:(要禁用此属性)


在TextInputLayout的父视图中添加属性
android:focusableInTouchMode=“true”
,如下所示

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusableInTouchMode="true">
    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ............>
        <android.support.v7.widget.AppCompatEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ............/>
    </android.support.design.widget.TextInputLayout>
</RelativeLayout>

我尝试在您不想自动对焦的EditText之前添加另一个EditText,但效果良好

<EditText
      android:layout_width="0dp"
      android:layout_height="0dp" />
    <android.support.design.widget.TextInputLayout
        android:id="@+id/NghiPhep_TextInputLayout_GhiChu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:hintTextAppearance="@style/TextHintLabel"
        android:layout_marginTop="5dp"
        android:focusableInTouchMode="true"
        >
        <EditText
            android:id="@+id/NghiPhep_txt_GhiChu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/colorPrimaryDark"
            android:hint="Ghi chú"
            android:fontFamily="@font/arial_rounded"
            android:inputType="textMultiLine"
            android:singleLine="false"
            android:textSize="18sp"/>
    </android.support.design.widget.TextInputLayout>


嘿,Josh,这将隐藏软键盘,但焦点仍然只在那里。而且我也无法更改颜色。很高兴它在@Naveenshryan起作用,它还帮助我达到1K点XDI将
安卓:focusable=“true”
安卓:focusableInTouchMode=“true”
放在父布局上;工作得很好。谢谢,我在前两天一直在找这个。来看看堆栈溢出!您是否可以添加一点解释,说明为什么以及该代码片段如何准确地提供问题的答案?谢谢工作得很有魅力!谢谢;)工作得很有魅力!谢谢;)但是键盘还是会弹出,怎么防止呢?
<EditText
      android:layout_width="0dp"
      android:layout_height="0dp" />
    <android.support.design.widget.TextInputLayout
        android:id="@+id/NghiPhep_TextInputLayout_GhiChu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:hintTextAppearance="@style/TextHintLabel"
        android:layout_marginTop="5dp"
        android:focusableInTouchMode="true"
        >
        <EditText
            android:id="@+id/NghiPhep_txt_GhiChu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/colorPrimaryDark"
            android:hint="Ghi chú"
            android:fontFamily="@font/arial_rounded"
            android:inputType="textMultiLine"
            android:singleLine="false"
            android:textSize="18sp"/>
    </android.support.design.widget.TextInputLayout>