editext没有获得焦点约束布局

时间:2018-05-02 13:12:34

标签: android android-layout android-edittext android-constraintlayout

我为我的布局编辑文本添加了xml没有获得焦点,只选择第一个然后无法选择另一个edittext screen ui with multiple edit texts

恐怕无论如何焦点都没有得到或者搞砸了,但无论如何也无法解决它。

也许constraintlayout是罪魁祸首,但不知道。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar_layout" />

    <ScrollView
        android:id="@+id/svScroll"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:padding="10dp"
        android:scrollbars="none"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar"
        app:layout_constraintBottom_toTopOf="@+id/btUpdate"
        >

        <android.support.constraint.ConstraintLayout
            android:id="@+id/constraint_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/black"
            >

            <EditText
                android:id="@+id/etEmailid"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:background="@drawable/profile_background"
                android:hint="@string/email_txt"
                android:padding="10dp"
                android:textColor="@color/white"
                android:textColorHint="@color/white"
                android:textSize="16sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                android:inputType="text" />

            <EditText
                android:id="@+id/etFirstName"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/profile_background"
                android:padding="10dp"
                android:hint="@string/First_name"
                android:textColorHint="@color/white"
                android:textColor="@color/white"
                android:textSize="16sp"
                android:inputType="textCapWords"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/etEmailid"
                />

            <EditText
                android:id="@+id/etLastName"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/profile_background"
                android:padding="10dp"
                android:hint="@string/last_name"
                android:inputType="textCapWords"
                android:textColorHint="@color/white"
                android:textColor="@color/white"
                android:textSize="16sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/etFirstName" />

            <TextView
                android:id="@+id/dob"
                android:layout_width="0dp"
                android:layout_height="50dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/profile_background"
                android:drawablePadding="10dp"
                android:drawableEnd="@mipmap/mdate"
                android:gravity="center_vertical"
                android:padding="10dp"
                android:hint="@string/dob"
                android:textColorHint="@color/white"
                android:textColor="@color/white"
                android:textSize="16sp"
                app:layout_constraintEnd_toStartOf="@+id/genderSpinner"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/etLastName" />

            <Spinner
                android:id="@+id/genderSpinner"
                android:layout_width="0dp"
                android:layout_height="50dp"
                android:layout_marginStart="10dp"
                android:background="@drawable/profile_background"
                android:entries="@array/gender"
                android:textColor="@color/white"
                android:textColorHint="@color/white"
                android:textSize="16sp"
                app:layout_constraintBottom_toBottomOf="@+id/dob"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/dob"
                app:layout_constraintTop_toTopOf="@+id/dob"/>

            <EditText
                android:id="@+id/etMobileno"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/profile_background"
                android:padding="10dp"
                android:hint="@string/mobile_txt"
                android:textColor="@color/white"
                android:textColorHint="@color/white"
                android:textSize="16sp"
                android:inputType="number"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/genderSpinner" />

            <EditText
                android:id="@+id/etAddress"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/profile_background"
                android:padding="10dp"
                android:hint="@string/address"
                android:inputType="textCapWords"
                android:textColorHint="@color/white"
                android:textColor="@color/white"
                android:textSize="16sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/etMobileno" />


            <EditText
                android:id="@+id/etCity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/profile_background"
                android:padding="10dp"
                android:hint="@string/S_city"
                android:textColor="@color/white"
                android:textColorHint="@color/white"
                android:textSize="16sp"
                android:inputType="textCapWords"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/etAddress" />

            <EditText
                android:id="@+id/etPincode"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/profile_background"
                android:padding="10dp"
                android:hint="@string/pincode"
                android:textColor="@color/white"
                android:textColorHint="@color/white"
                android:textSize="16sp"
                android:inputType="number"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/etCity" />

            <TextView
                android:id="@+id/tvMandatory"
                android:layout_width="match_parent"
                android:layout_height="12dp"
                android:layout_marginTop="10dp"
                android:text="@string/mandatory"
                android:textColor="@color/white"
                android:textSize="10sp"
                android:gravity="right"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/etPincode" />


            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/ivProfile"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_marginTop="10dp"
                android:src="@drawable/prof_img"
                app:civ_border_color="#000"
                app:civ_border_width="0.5dp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/tvMandatory" />

            <TextView
                android:id="@+id/tvChoosePhoto"
                android:layout_width="150dp"
                android:layout_height="40dp"
                android:layout_marginLeft="16dp"
                android:background="@drawable/prof_cam"
                android:gravity="center|left"
                android:paddingLeft="@dimen/plus_15dp"
                android:text="CHOOSE YOUR PHOTO"
                android:textColor="@color/black"
                android:textSize="10sp"
                app:layout_constraintBottom_toBottomOf="@+id/ivProfile"
                app:layout_constraintLeft_toRightOf="@+id/ivProfile"
                app:layout_constraintTop_toTopOf="@+id/ivProfile" />

            <TextView
                android:id="@+id/tvClear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="32dp"
                android:gravity="center|left"
                android:text="@string/clear"
                android:textColor="@color/white"
                app:layout_constraintBottom_toBottomOf="@+id/tvChoosePhoto"
                app:layout_constraintLeft_toRightOf="@+id/tvChoosePhoto"
                app:layout_constraintTop_toTopOf="@+id/tvChoosePhoto"
                tools:ignore="MissingConstraints" />
        </android.support.constraint.ConstraintLayout>
    </ScrollView>
    <Button
        android:id="@+id/btUpdate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_update"
        android:text="UPDATE"
        android:layout_marginBottom="10dp"
        android:textColor="@color/white"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        app:layout_constraintBottom_toBottomOf="parent"
        />

</android.support.constraint.ConstraintLayout>

这表明我在constraintlayout中使用了scrollview,它有多个编辑文本,无法聚焦第二个或任何其他元素

1 个答案:

答案 0 :(得分:0)

您可以使用android:imeOptions="actionNext"将焦点放在布局中的下一个EditText项目上。我在Scrollview中的ConstrainLayout中使用了EditText(或AppCompatEditText),它工作正常。