1 简介

本文主要介绍通过 shape 来设置 EditText 的圆角。
 

2 shape 的设置

 

shape_life_search.xml 放在 res/drawable 文件夹内

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 角度 -->
<corners android:radius="100dp"/>
<!-- 填充色 -->
<solid android:color="#ffffff"/>
<!-- 描边 设置线宽及颜色 -->
<stroke android:color="#cccacb"
android:width="1dp"/>
</shape>
 

3 shape 的使用

 
在 activity_main.xml 主布局中如此使用

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#f5f5f5"
tools:ignore="HardcodedText,ContentDescription" > <!-- Head start -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:background="#ff5a54">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/head_left" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="周边生活"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@android:color/white"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/head_right" />
</LinearLayout>
<!-- Head end -->
<!-- Search start-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp">
<EditText
android:id="@+id/search_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/search_left"
android:background="@drawable/shape_life_search"
android:hint="请输入商户或地址"
android:padding="10dp"
android:textColorHint="#b7b7b7"
android:textStyle="bold"/>
</LinearLayout>
<!-- Search end -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>

4 用到的资源

 
head_left.png


head_right.png


search_left.png


 

 

5 隐藏标题栏

package com.ui;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //隐藏应用程序标题栏 (能看到手机通知栏)
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置全屏 (手机通知栏也被隐藏)
//this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main);
}
}

6 结果预览

 
注:在 eclipse 的 layout 布局预览功能中,圆角不是很明显,但是安装到模拟器后就正常显示了,具体原因未知。
 
在 eclipse 中预览结果
 
在模拟器中的结果
 






 注:转载请注明出处 :)   毕竟代码是一个一个敲出来的啊,O(∩_∩)O~



 
 
 

Android 之 Shape (圆角输入框)的更多相关文章

  1. Android GradientDrawable(shape标签定义) 静态使用和动态使用(圆角,渐变实现)

    Android GradientDrawable使用优势: 1. 快速实现一些基本图形(线,矩形,圆,椭圆,圆环) 2. 快速实现一些圆角,渐变,阴影等效果 3. 代替图片设置为View的背景 4. ...

  2. 44.Android之Shape设置虚线、圆角和渐变学习

    Shape在Android中设定各种形状,今天记录下,由于比较简单直接贴代码. Shape子属性简单说明一下:  gradient -- 对应颜色渐变. startcolor.endcolor就不多说 ...

  3. Android UI(一)Layout 背景局部Shape圆角设计

    Jeff Lee blog:   http://www.cnblogs.com/Alandre/  (泥沙砖瓦浆木匠),retain the url when reproduced ! Thanks ...

  4. Android之shape与selector实现圆角

    shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和 ...

  5. Drawable实战解析:Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)

    Android XML shape 标签使用详解   一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...

  6. android 使用shape来优化界面效果

    看下效果图: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android=&quo ...

  7. 转 Android中shape中的属性大全

    <shape>            <!-- 实心 -->            <solid android:color="#ff9d77"/&g ...

  8. [Android UI] shape和selector的结合使用

    shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和 ...

  9. Android之shape属性详解

    有时候 ,为了满足一些需求,我们要用到 shape 去定义 一些背景,shape 的用法 跟图片一样 ,可以给View设置 Android:background="@drawable/sha ...

随机推荐

  1. Linux常见面试题

      一.填空题:1. 在Linux系统中,以 文件 方式访问设备 .2. Linux内核引导时,从文件 /etc/fstab 中读取要加载的文件系统.3. Linux文件系统中每个文件用 索引节点来标 ...

  2. 关于在xp(sp3 专业版)下安装sql2005开发版图解

    今天我在xp上安装sql2005,搞了一上午也没有搞好,最终自己还是搞好,也装了,也卸载了!这里就总结一下,让以后用sql2005的朋友能有个参考!我也是自己在GOOGLE上搜索的! 转自:http: ...

  3. FoxOne---一个快速高效的BS框架--(2)

    FoxOne---一个快速高效的BS框架--(1) FoxOne---一个快速高效的BS框架--(2) FoxOne---一个快速高效的BS框架--(3) FoxOne---一个快速高效的BS框架-- ...

  4. linux防火墙开启-关闭

    1.永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2. 即时生效,重启后复原 开启: service iptab ...

  5. mybatis 与 反射

    Mybatis是个优秀的ORM框架,所以它的反射层一定不会让我们失望 图比较大,可以开新页面查看 可以看到,Mybatis对这一块抽象的比较复杂,我们可以看到有几个比较主要的部分:Reflector. ...

  6. Jdbc 事务

    package com.j1; import java.sql.Connection; import java.sql.SQLException; import com.mysql.jdbc.Prep ...

  7. js实现数字分页

    ///js数字分页 返回数组function page(pageCount, sideNum, pageNum) {    //其实页    var startNum = 0;    //结束页    ...

  8. css3背景总结与解析

    一.常用基本属性: background-color:transparent || <color>        常用颜色格式有:颜色名.rgb.hls.十六进制.rgba.hlsa. b ...

  9. 调用有道翻译API

    前两天朋友说起NASA开放了数据API,今儿突然想起从来没用过外部提供的API,然而简单用得多的貌似是有道词典API,就像试试,本来觉得应该挺简单的,用urllib模块很快就实现了. 不过测试时才发现 ...

  10. jdbc 获取connection 对象的三种方式

    获取数据库连接方法一:驱动实现类 //创建mysql的Driver对象 Driver driver=new com.mysql.jdbc.Driver(); //jdbc url 定位一个数据库: S ...