Android EditText在其drawable和其文本之间绘制分隔线 [英] Android EditText draw a divider line between its drawable and its text

查看:150
本文介绍了Android EditText在其drawable和其文本之间绘制分隔线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EditText和一个drawableLeft图像.我需要在drawableLeft旁边的EditText中添加一条垂直线,例如以下示例:

I have an EditText with a drawableLeft image. I need to add a vertical line in EditText right beside my drawableLeft like this example:

我能想到的最简单的方法是将那条线添加到我的可绘制图像中.但是通常还有其他方法可以做到这一点吗?

Easiest way that I can think of is to add that line into my drawable image. But generally is there any other way to do this?

推荐答案

  1. 在res/drawable/shape.xml中创建矩形圆角形状

  1. Create a rectangular rounded corner shape in res/drawable/shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="3dip" android:color="@android:color/darker_gray" />
<corners android:radius="10dip"/>
<padding android:left="10dip" android:top="10dip" android:right="10dip"        android:bottom="10dip" />
</shape>

  • 现在创建布局

  • Now create a layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/shape"
    android:gravity="center_vertical">
    
    
    <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:src="@drawable/ic_launcher"/>
    
    <View
    android:layout_width="2dp"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray"
    android:layout_marginLeft="10dp"/>
    
    <EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/editText"
    android:layout_weight="1"
    android:background="@null"
    android:layout_marginLeft="10dp"
    android:hint="Your bitcoin address here"/>
    
    
    </LinearLayout>
    

  • 我已将线性布局背景设置为矩形圆角形状.它看起来与urs的图像预览完全一样.

  • I have set the Linear layout background with th rectangular rounded corner shape. It looks exactly as the image preview of urs.

    这篇关于Android EditText在其drawable和其文本之间绘制分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆