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>



  • 相关阅读:
    普林斯顿宣布开源 25 核处理器
    瑞芯微RK3399宣布系统开源,进入百余种行业市场!
    Qt浅谈之二十App自动重启及关闭子窗口
    学在LINUX下编程(各种情况比较详细)
    ASP.NET开发规范:OWIN
    IDEA14中安装go语言插件
    sqlserver不能直接create table as select
    表复制语句select into from 与 insert into select 区别鉴赏
    实现Asp.net Mvc分布式Session Redis群集
    大小端模式
  • 原文地址:https://www.cnblogs.com/krislight1105/p/3748320.html
Copyright © 2011-2022 走看看