如何使用下面的EditText XML(形状)来设置线作为背景? [英] How to set line as a background using xml (shape) below to EditText?

查看:466
本文介绍了如何使用下面的EditText XML(形状)来设置线作为背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用形状XML来设置线路如下的EditText背景,但是当我把它放在中心线上设置

我要像下面

但是当我设置为低于

形状

绘制/ line.xml


 <?XML版本=1.0编码=UTF-8&GT?;
<形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:造型=行>
<中风
    机器人:身高=4DP
    机器人:颜色=@色/ crabfx_dark_gray/>
< /形状>


activity_main.xml中


 <的EditText
    机器人:ID =@ + ID / EDT
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:文字颜色=@机器人:彩色/黑白
    机器人:layout_margin =20dp
    机器人:背景=@绘制/线路/>


我得到了下面的输出

什么方法解决?


解决方案

试试这个我希望你能得到完美的解决方案。

 <?XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android><项目>
    <形状和GT;
        [固体机器人:色=@彩色/灰度/>
    < /形状>
< /项目><! - 主色 - >
<项目
    机器人:底部=1DP
    机器人:左=1DP
    机器人:右=1DP>
    <形状和GT;
        [固体机器人:色=@色/白/>
    < /形状>
< /项目>&所述;! - 绘制另一个块来切断左和右杆 - >
<项目的android:底部=1DP>
    <形状和GT;
        [固体机器人:色=@色/白/>
    < /形状>
< /项目>< /层列表>

或者试试这个

 <?XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android><项目>
    <形状和GT;
        [固体机器人:色=@彩色/灰度/>
    < /形状>
< /项目><项目
    机器人:底部=1像素
    机器人:左=0像素>
    <形状机器人:形状=矩形>
        [固体机器人:颜色=#FFFFFF/>
    < /形状>
< /项目>< /层列表>

I want to set the line as background below EditText using shape xml but when I set it line set on center

I want like below

but when I set the shape below

drawable/line.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
    android:height="4dp"
    android:color="@color/crabfx_dark_gray" />
</shape>

activity_main.xml

<EditText
    android:id="@+id/edt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@android:color/black"
    android:layout_margin="20dp" 
    android:background="@drawable/line"/>

I got below output

is any solution ?

解决方案

Try this one i hope you will get perfect solution..

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape>
        <solid android:color="@color/gray" />
    </shape>
</item>

<!-- main color -->
<item
    android:bottom="1dp"
    android:left="1dp"
    android:right="1dp">
    <shape>
        <solid android:color="@color/white" />
    </shape>
</item>

<!-- draw another block to cut-off the left and right bars -->
<item android:bottom="1dp">
    <shape>
        <solid android:color="@color/white" />
    </shape>
</item>

</layer-list>

Or Try this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape>
        <solid android:color="@color/gray" />
    </shape>
</item>

<item
    android:bottom="1px"
    android:left="0px">
    <shape android:shape="rectangle" >
        <solid android:color="#FFFFFF" />
    </shape>
</item>

</layer-list>

这篇关于如何使用下面的EditText XML(形状)来设置线作为背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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