简体   繁体   中英

Kotlin can't click on empty EditText

I am creating a profile activity and each row contain on one side a textview for the information about the row for exemple : Name, on the other side i have an EditText to change the information when we click on validate. here is the xml for each row :

    <FrameLayout
            android:id="@+id/first_name_row"
            android:layout_marginBottom="@dimen/profile_row_bottom_margin"
            android:background="@color/white"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:foreground="?android:attr/selectableItemBackground">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/small_item_list_height"
                android:paddingEnd="@dimen/default_padding"
                android:paddingLeft="@dimen/default_padding"
                android:paddingRight="@dimen/default_padding"
                android:paddingStart="@dimen/default_padding">

                <TextView
                    android:includeFontPadding="false"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_centerVertical="true"
                    android:layout_marginEnd="@dimen/default_padding"
                    android:layout_marginRight="@dimen/default_padding"
                    android:text="@string/acct_first_name"
                    android:textSize="@dimen/profile_row_text_size" />

                <EditText
                    android:id="@+id/acc_name_first"
                    android:includeFontPadding="false"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:layout_marginEnd="@dimen/default_padding"
                    android:layout_marginRight="@dimen/default_padding"
                    android:background="@null"
                    android:text="@string/acct_first_name"
                    android:enabled="false"
                    android:focusable="false"
                    android:cursorVisible="false"
                    android:textSize="@dimen/profile_row_text_size" />

            </RelativeLayout>
        </FrameLayout>

The problem is that I added android:background="@null" because I don't want the bar under the field. but when I do that I delete all character from the field, it's become empty and if I change to focus on another field, I can't click on the empty field.

个人资料图片

Here you have the image, the field Nom is selected but we see that the field prename is empty so I can't select it. also, the field email work because I didn't put backgound = null but I don't want the bar under it.

Is there a way to have a Textedit that doesn't have a bar under it but can still be clickable is it's empty?

EditText has android:layout_width="wrap_content" once you remove all the char with becomes zero, next time even if you enable it you cannot click it. Use attribute android:minEms="1" .

From my point of view it will be better to just add some minimum width to your edit text:

<EditText
    android:id="@+id/acc_name_first"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginEnd="@dimen/default_padding"
    android:layout_marginRight="@dimen/default_padding"
    android:background="@null"
    android:cursorVisible="false"
    android:enabled="false"
    android:focusable="false"
    android:includeFontPadding="false"
    android:minWidth="50dp"
    android:text="@string/acct_first_name"
    android:textSize="@dimen/profile_row_text_size" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM