如何删除android中edittext字段的边框

时间:2013-01-07 15:46:14

标签: android android-layout

如何在android中删除Edittext字段的边框。实际上它看起来像这样

http://pbrd.co/V34sN7

使用此布局代码

    <EditText
        android:id="@+id/login_error"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:background="@android:drawable/editbox_background_normal"
        android:visibility="invisible" 
        android:textColor="#FF0000"
        android:layout_gravity="right"
        />

尽管我定义了文本,但文本的对齐方式并不在右侧。

由于

4 个答案:

答案 0 :(得分:15)

简单地说,您可以在xml文件中使用以下内容,使EditText背景清晰:

android:background="@null"

答案 1 :(得分:6)

程序化方法:

setBackgroundDrawable(null);

或者,因为在API 16中不推荐使用setBackgroundDrawable():

if (getApiLevel() >= 16) // Suppose we wrote getApiLevel() helper to get the API level
    setBackground(null);
else
    setBackgroundDrawable(null);

答案 2 :(得分:5)

您可以使用以下xml布局

自定义EditText

将以下代码保存为yourWishName.xml

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

//You can change the color of the edit text here which removes the border line as well
 <item android:state_focused="true" >
    <shape android:shape="rectangle">
        <gradient
            android:startColor="#FFFFFF"
            android:endColor="#FFFFFF"
            android:angle="270" />
        <stroke
            android:width="3dp"
            android:color="#F8B334" />
        <corners
            android:radius="12dp" /> 
    </shape>
</item>  
<item>
    <shape android:shape="rectangle">
        <gradient
            android:startColor="#FFFFFF"
            android:endColor="#FFFFFF"
            android:angle="270" />
        <stroke
            android:width="0dp"
            android:color="#000000" />
        <corners
            android:radius="12dp" /> 
    </shape>
</item>
</selector>

在EditText中调用xml android:background="@drawable/yourWishName"

右对齐使用android:gravity="right"

希望这有帮助

答案 3 :(得分:3)

你必须创建一个没有边框的自定义可绘制九个补丁文件。 Here you find a tutorialandroid:layout_gravity="right"并不意味着文字与右边对齐。它将布局与右对齐。您必须使用android:gravity="right"