简体   繁体   English

如何在android中创建带圆角的编辑文本

[英]How to create edit text with rounded corners in android

Can anybody tell me how to create an editable textbox with rounded corners in android? 任何人都可以告诉我如何在android中创建一个带圆角的可编辑文本框?

I tried with this code but it's not working: 我尝试使用此代码,但它不起作用:

<?xml version="1.0" encoding="utf-8"?> 
<!--  res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">
    <solid android:color="#FFFFFF" />
    <corners android:bottomRightRadius="0dp"
        android:bottomLeftRadius="0dp" android:topLeftRadius="15dp"
        android:topRightRadius="15dp" />
</shape> 

Thanks 谢谢

Hey have a look about the problem in this discussion : How to create EditText with rounded corners? 嘿,看看这个讨论中的问题: 如何创建带圆角的EditText? ..I am sure it will surely gonna help you. ..我相信它肯定会帮到你。

Just create an xml file in your drawable folder name as round_corner.xml .And add this following code. 只需在drawable文件夹名称中创建一个xml文件作为round_corner.xml 。并添加以下代码。

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

        <corners
            android:bottomLeftRadius="3dp"
            android:bottomRightRadius="3dp"
            android:radius="3dp"
             />
        <solid
            android:color="@android:color/white"/>

    </shape>

At Last you add this xml in background property of your Edittext as follows:- 最后,您可以在Edittext的 background属性中添加此xml,如下所示: -

<EditText
   android:id="@+id/ed1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@drawable/round_corner"
 />

Done..Definitely it works.. 完成..无限期它有效..

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#ECE9E6"
        android:endColor="#FFFFFF"
        android:angle="270"
        />
    <corners
        android:radius="15dp" />
    <stroke
        android:width="1dip"
        android:color="#ffffff"
        />
    <padding
        android:left="4dp"
        android:top="4dp"
        android:right="4dp"
        android:bottom="4dp"
        />
</shape>

Use This Code 使用此代码

 <?xml version="1.0" encoding="utf-8"?>
 <!-- res/drawable/rounded_edittext.xml --> 
<shape xmlns:android="schemas.android.com/apk/res/android"; android:shape="rectangle" android:padding="10dp"> <solid android:color="#FFFFFF" > 

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

</shape>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM