Android EditText draw a divider line between its drawable and its text(Android EditText 在其可绘制对象和文本之间绘制分隔线)
问题描述
我有一个带有 drawableLeft 图像的 EditText.我需要在我的 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?
推荐答案
在 res/drawable/shape.xml 中创建一个矩形圆角形状
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 在其可绘制对象和文本之间绘制分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android EditText 在其可绘制对象和文本之间绘制分隔
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
