Java 如何删除edittext字段的边框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20811850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:31:12  来源:igfitidea点击:

how to remove border of edittext field

javaandroidandroid-layoutlayoutandroid-edittext

提问by Android Learner

I have created a login layout but in this layout edittext field border is overlap. I want to remove the top borderof second edit text field. please guide me. here is the link screen

我创建了一个登录布局,但在这个布局中,edittext 字段边框是重叠的。我想删除top border第二个编辑文本字段。请指导我。这是链接 屏幕

I want to make layout exactly like this. Here is my XML code.

我想让布局完全像这样。这是我的XML code.

round_edittext.xml:

round_edittext.xml:

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

    <solid android:color="#FFFFFF" />

    <stroke
        android:width="1dp"
        android:color="#9999" />

    <corners
        android:bottomLeftRadius="1dp"
        android:bottomRightRadius="1dp"
        android:topLeftRadius="1dp"
        android:topRightRadius="1dp" />

</shape>

activity_mail.xml:

活动邮件.xml:

<?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="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/save"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:clickable="false"
        android:src="@drawable/no_smslogo_text" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40sp"
        android:layout_marginRight="40sp"
        android:layout_marginTop="10sp"
        android:background="@drawable/round_edittext"
        android:drawableLeft="@drawable/mobile_icon"
        android:drawablePadding="5dp"
        android:gravity="left"
        android:hint="Mobile Number"
        android:padding="5dp"
        android:paddingBottom="8sp"
        android:paddingTop="8sp"
        android:textSize="15dp" >
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40sp"
        android:layout_marginRight="40sp"
        android:background="@drawable/round_edittext"
        android:drawable="@drawable/pin_icon"
        android:drawableLeft="@drawable/mobile_icon"
        android:drawablePadding="5dp"
        android:gravity="left"
        android:hint="Pin Number"
        android:padding="5dp"
        android:paddingBottom="8sp"
        android:paddingTop="8sp"
        android:textSize="15dp" />

    <Button
        android:id="@+id/signin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40sp"
        android:layout_marginRight="40sp"
        android:layout_marginTop="10sp"
        android:clickable="true"
        android:gravity="center"
        android:text="Sign In"
        android:textColor="#ffffff"
        android:textSize="15dp" />

</LinearLayout>

回答by sachin10

you need to use layer list for this

您需要为此使用图层列表

 <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- Border -->
    <item>
        <shape>
            <solid android:color="#f000"></solid>
        </shape>
    </item>
    <!-- Body -->
    <item android:left="2dip"
          android:bottom="2dp"
          android:right="2dp">
        <shape>
            <solid android:color="#ffafafaf"></solid>
        </shape> 
    </item>
</layer-list>

回答by SuN

You have two solution for this

你有两个解决方案

  1. You can set shape on layout background and put two edit text in the layout.

  2. Currently you're using one shape for edit text round. You can use two shapes; different ones that have upper border and other have bellow border.

  1. 您可以在布局背景上设置形状并在布局中放置两个编辑文本。

  2. 目前您正在使用一种形状来编辑文本圆。您可以使用两种形状;不同的有上边界和其他有波纹管边界。

<ImageButton
    android:id="@+id/save"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#00000000"
    android:clickable="false" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/round_edittext"
    android:gravity="center"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40sp"
        android:layout_marginRight="40sp"
        android:layout_marginTop="10sp"
        android:background="#00000000"
        android:drawablePadding="5dp"
        android:gravity="left"
        android:hint="Mobile Number"
        android:padding="5dp"
        android:paddingBottom="8sp"
        android:paddingTop="8sp"
        android:textSize="15dp" >
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40sp"
        android:layout_marginRight="40sp"
        android:background="#00000000"
        android:drawablePadding="5dp"
        android:gravity="left"
        android:hint="Pin Number"
        android:padding="5dp"
        android:paddingBottom="8sp"
        android:paddingTop="8sp"
        android:textSize="15dp" />
</LinearLayout>

<Button
    android:id="@+id/signin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="40sp"
    android:layout_marginRight="40sp"
    android:layout_marginTop="10sp"
    android:clickable="true"
    android:gravity="center"
    android:text="Sign In"
    android:textColor="#ffffff"
    android:textSize="15dp" />

回答by The Ray of Hope

You can customise your edit text by using the following xml layout

您可以使用以下 xml 布局自定义编辑文本

Save the following code asyourWishName.xml

将以下代码保存为 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>

In EditText call the xml android:background="@drawable/yourWishName"

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

To Align right Use android:gravity="right"

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

Hope this helps

希望这可以帮助

回答by Hamad

use two drawables for your edittext.

为您的编辑文本使用两个可绘制对象。

One with padding top:

一种带衬垫顶部:

round_edittext.xml:

round_edittext.xml:

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

<solid android:color="#FFFFFF" />

<stroke
    android:width="1dp"
    android:color="#9999" />
<!-- add this padding for top -->
<padding android:top="2dp" />
<corners
    android:bottomLeftRadius="1dp"
    android:bottomRightRadius="1dp"
    android:topLeftRadius="1dp"
    android:topRightRadius="1dp" />

</shape>

and Second without padding:

第二个没有填充:

round_edittext.xml:

round_edittext.xml:

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

<solid android:color="#FFFFFF" />

<stroke
    android:width="1dp"
    android:color="#9999" />

<corners
    android:bottomLeftRadius="1dp"
    android:bottomRightRadius="1dp"
    android:topLeftRadius="1dp"
    android:topRightRadius="1dp" />

</shape>

回答by RaviPatidar

Use it, this is working for me

使用它,这对我有用

<EditText  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:hint="@string/hello" 
android:background="#00000000"
/>