带有图标/按钮的Android EditText

Ion*_*uta 4 android android-edittext

我怎样才能获得EditText那些吼叫?

在此输入图像描述

x按钮删除插入的文本,只要按下,眼睛按钮就会显示清除密码.请注意,我将它们称为按钮,因为我不知道它们实际上是什么,也不知道它们是EditText本身的一部分还是它们是独立的视图.

Vas*_*nov 9

您只需在EditText右侧添加一个按钮即可

<FrameLayout
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/ScreenLoginContainer">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/edit_text_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:imeOptions="actionDone"
            android:hint="@string/enter_password_hint"
            android:paddingRight="30dp"
            style="@style/ScreenPasswordEditText"/>

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

    <Button
        android:id="@+screen_card_ean_enter/show_password_button"
        style="@style/ShowHidePasswordButton"/>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)


Int*_*iya 5

您可以使用 android:drawableRight

设置一个可绘制的文本的右侧,在EditText上,在XML。

android:drawableRight="@drawable/Your_drawable"
Run Code Online (Sandbox Code Playgroud)

  • 但是,您将如何处理onClick? (3认同)
  • @ user2143491您可以关注/sf/answers/1838860481/ (2认同)