zoukankan      html  css  js  c++  java
  • 带圆角的EditText

    转载请注明出处:http://blog.csdn.net/krislight/article


    1.定义一个Drawable

    <?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="15dp"
         android:bottomLeftRadius="15dp"
      android:topLeftRadius="15dp"
      android:topRightRadius="15dp"/>
    </shape>


    2.布局文件

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <EditText  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:padding="5dip"
        android:background="@drawable/rounded_edittext" />
    </LinearLayout>


    如果要使用多个不同状态下的EditText点击效果

    1.定义一个selector

    <?xml version="1.0" encoding="utf-8"?>
    <!-- res/drawable/rounded_edittext_states.xml -->
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item 
         android:state_pressed="true" 
         android:state_enabled="true"
            android:drawable="@drawable/rounded_focused" />
        <item 
         android:state_focused="true" 
         android:state_enabled="true"
            android:drawable="@drawable/rounded_focused" />
        <item 
         android:state_enabled="true"
            android:drawable="@drawable/rounded_edittext" />
    </selector>

    2.定义Drawable

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


    3.布局文件

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <EditText  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        android:background="@drawable/rounded_edittext_states"
        android:padding="5dip"/>
    </LinearLayout>



  • 相关阅读:
    Elasticsearch入门系列(一)
    清楚Chrome缓存
    解决IIS启动站点报错
    Input type="file"上传文件change事件只触发一次解决方案
    本地计算机上的XXX服务启动后停止,某些服务在未由其它服务或程序使用时将自动停止
    SQL Server Datetime类型为NULL不能用ISNULL(datetime,' ')来判断,会导致1900-01-01
    浏览指南
    谁发明的c++
    c++的用处
    不一样的二叉树遍历(小学生都会)
  • 原文地址:https://www.cnblogs.com/krislight1105/p/3748320.html
Copyright © 2011-2022 走看看