Android:EditText嵌入图片并且响应

17 篇文章 0 订阅
分享一种不用drawableLeft的快速设置EditText和ImageView布局的方法,通过调整background清除 EditText 下划线,再自定义LinearLayout背景。点击事件轻松添加。
摘要由CSDN通过智能技术生成

并不一定要用android:drawableLeft="@drawable/icon"这种方法
教大家一种简单

在这里插入图片描述

稍微说一下这个布局

其实就是LinearLayout横向布局套了两个控件,一个EditText,一个ImageView
要注意的是,EditText他有下划线那些样式,通过这个android:background="@null"清除掉就可以
最后LinearLayout加个背景就行了

emmm,我是不是讲复杂了

看图能不能理解

在这里插入图片描述

<LinearLayout
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:background="@drawable/edit_background"
            android:layout_height="wrap_content">

            <EditText
                android:textSize="14dp"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:enabled="true"
                android:gravity="top"
                android:inputType="textMultiLine"
                android:minHeight="20dp"
                android:minLines="2"
                android:maxLines="2"
                android:scrollbars="vertical"
                android:background="@null"
                />

            <ImageView
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:padding="9dp"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:src="@mipmap/share_icon"
                ></ImageView>

        </LinearLayout>

这个是android:background="@drawable/edit_background"对应的样式

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape
            android:shape="rectangle">
            <solid android:color="#efefef"/>
            <corners android:radius="5dp"/>
            <stroke
                android:width="1dp"
                android:color="#505050"/>
        </shape>
    </item>
    </layer-list>

响应我就不用多说了吧,给图片添加一个点击事件就可以了。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wenlong Yang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值