Android EditText 在其可绘制对象和文本之间绘制分隔线

Android EditText draw a divider line between its drawable and its text(Android EditText 在其可绘制对象和文本之间绘制分隔线)
本文介绍了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?

推荐答案

  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 在其可绘制对象和文本之间绘制分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

    本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!
  • 相关文档推荐

    How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
    cocos2d-android: how to display score(cocos2d-android:如何显示分数)
    Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
    SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
    Android file copy(安卓文件拷贝)
    Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)