我有一个带有 drawableLeft
图像的 EditText
。我需要在 drawableLeft
旁边的 EditText
中添加一条垂直线,如下例所示:
我能想到的最简单的方法是将该线添加到我的可绘制图像中。但是通常有没有其他方法可以做到这一点?
最佳答案
在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>
现在创建一个布局
<?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>
我已将线性布局背景设置为矩形圆角形状。它看起来和你的图片预览一模一样。
关于Android EditText 在其可绘制对象和文本之间绘制一条分隔线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34541433/