Android上的自定义editText [英] Custom editText on android

查看:399
本文介绍了Android上的自定义editText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android布局的新手,所以我需要一些帮助.

I'm newbie with android layout, so i need some help.

我想创建一个自定义的editText,如下所示:

I want create a custom editText, something like this:

我想以最好的方式修复它.

I'm want to fix that with the best possible way.

有人吗?

谢谢.

推荐答案

如果您想在左侧显示蓝线,只需在EditText上设置背景,例如

If you want the blue line on the left, you can just set the background on the EditText, such as,

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:background="@drawable/custom_edittext"
        android:layout_weight="1" />

然后在可绘制文件夹中创建另一个文件,该文件称为custom_layer.xml

Then create another file in your drawable folder this is called custom_layer.xml

   <?xml version="1.0" encoding="utf-8"?>
   <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:bottom="-5dp"
        android:right="-5dp"
        android:top="-5dp">
        <shape android:shape="rectangle" >
            <solid android:color="@color/color_of_the_background" />
            <stroke
                android:width="5dp"
                android:color="@color/color_of_the_border" />
        </shape>
    </item>
</layer-list>

还有一个最终选择器文件-custom_edittext.xm.

And a final selector file - custom_edittext.xm.

<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/custom_layer">        
    </item>
</selector>

这篇关于Android上的自定义editText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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