【问题标题】:How to create edit text with rounded corners in android如何在android中创建带有圆角的编辑文本
【发布时间】:2011-07-29 03:07:05
【问题描述】:

谁能告诉我如何在android中创建一个带圆角的可编辑文本框?

我尝试使用此代码,但它不起作用:

<?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> 

谢谢

【问题讨论】:

  • 在 OS 2.3 之前,android 编辑文本的背景是圆角的。所以你可以做的是,将旧的背景图片复制到你的 res 文件夹中,然后在你的 xml 文件中手动设置它。

标签: android


【解决方案1】:
<?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>

【讨论】:

    【解决方案2】:

    只需在您的 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>
    

    最后,您在 Edittext 的 background 属性中添加此 xml,如下所示:-

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

    完成..绝对可以..

    【讨论】:

      【解决方案3】:

      使用此代码

       <?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>
      

      【讨论】:

        【解决方案4】:

        嘿,看看这个讨论中的问题:How to create EditText with rounded corners? ..我相信它一定会帮助你。

        【讨论】:

          猜你喜欢
          • 2010-12-13
          • 1970-01-01
          • 2011-04-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多