java - 如何从 drawableLeft android 中删除下划线

标签 java android android-layout

您好,我正在使用 editText 并为图像添加了 drawableLeft。但是下划线也出现在图像下方。

enter image description here

我正在使用下面的代码:

 <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_add_black_24dp"
            android:hint="@string/email"
            android:drawablePadding="10dp"
            android:layout_marginTop="10dp"/>

 <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_add_black_24dp"
            android:hint="@string/password"
            android:drawablePadding="10dp"
            android:layout_marginTop="10dp"
            android:inputType="textPassword"/>

请建议如何删除 drawableLeft(image) 下面的下划线。

最佳答案

没有任何直接的方法可以在 EditText 中获取这个东西。

你可以像下面这样使用它。

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/text_white"
        android:orientation="horizontal">

    <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_margin="@dimen/_10sdp"
            android:src="@drawable/ic_email"
            android:tint="@color/black"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/_10sdp"
            android:hint="email"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/imageView"
            app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

输出

enter image description here

关于java - 如何从 drawableLeft android 中删除下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57687010/

相关文章:

安卓工作室 : 'wrap in container' in XML layout

java - Clojure REPL,互操作,无法解析符号

java - 启动一个进程而不消耗它的输出

android - 用于在送货地址中添加当前位置的 Google map API

android - 404 找不到资源 lint-gradle-26.1.3.pom

Android 自定义选项卡内容

java - 如何在 JFreeChart 中用鼠标滚轮旋转饼图?

JavaFX TextArea 从坐标获取插入符位置

android - 有没有办法检查 WebView 内容是否对用户可见?

java - gridview 项目之间的完美线性间距