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. 函数返回char* 的解决方案

    在C语言中,自动变量在堆栈中分配内存.当包含自动变量的函数或代码块退出时,它们所占用的内存便被回收,它们的内容肯定会被下一个所调用的函数覆盖.这一切取决于堆栈中先前的自动变量位于何处,活动函数声明了什 ...

  2. 网页CSS1

    样式的属性 1,背景与前景 background-color: //背景的颜色 background-image:url //背景图片 background-attachment:fixed; //背 ...

  3. 根据控件Id得到控件

    在做动态获取控件时,时常需要根据Id得到控件,并对该控件进行操作,此时用 /// <summary>        /// 根据控件id得到控件        /// </summa ...

  4. spring的定时任务或者说自动任务

    http://kevin19900306.iteye.com/blog/1397744   //这个是别人的博客   引入除spring.jar外的Quartz的jar包quartz-all-1.8. ...

  5. css应用三

    1. Padding与margin Padding为内边距,padding值会计算在width和height之内.如:width:100px:height:100px:padding:10px:该di ...

  6. PHP二维数组排序函数

    PHP一维数组的排序可以用sort(),asort(),arsort()等函数,但是PHP二维数组的排序需要自定义. 以下函数是对一个给定的二维数组按照指定的键值进行排序,先看函数定义: functi ...

  7. ./configure 时候报错c++ 编译器不能执行

    ./configure时报错:configure: error: C++ compiler cannot create executables .哎,今天重装测试服务器上的系统,设置好IP可以远程访问 ...

  8. 消息机制 - Windows程序设计(SDK)004

    消息机制 让编程改变世界 Change the world by program 内容节选: 我们来回顾一下,窗口是怎么从代码中诞生出来的? 1. 首先我们是通过给 WNDCLASS 窗口类结构各个成 ...

  9. SelectedNode与e.node的区别

    SelectedNode与e.node的区别 待补.......

  10. java中把字节数组转换为16进制字符串

    把字符串数组转换为16进制字符串 import java.security.MessageDigest; public class StringUtil { public StringUtil() { ...