android自定义exittext和button
2015-09-02 02:26
330 查看
写项目往往要自定义exittext和button
1、自定义button有两种效果:圆角、默认颜色、点击时颜色
左图:带渐变效果,一般按钮是这种的。上面两种都是定义两个背景
默认色,没有点击的背景:
右图:和左图基本一样,就是点击不是渐变色:
上面两种效果的背景选择器:
2、自定义edittext
edittext默认的是一条线,一般需要边框的,如圆角、边框颜色、填充空白
有个简单的背景图利用系统自带的背景:@android:drawable/edit_background_normal或者@android:drawable/edit_background
效果图:
要嘛自定义背景:
1、自定义button有两种效果:圆角、默认颜色、点击时颜色
左图:带渐变效果,一般按钮是这种的。上面两种都是定义两个背景
默认色,没有点击的背景:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="@android:color/white"/> <corners android:radius="8px" /> </shape>点击后的背景:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="8px" /> <gradient android:angle="90" android:centerX="0.5" android:centerY="0.5" android:endColor="#CCCCCC" android:startColor="#888888" android:type="linear" /> </shape>
右图:和左图基本一样,就是点击不是渐变色:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="@android:color/white"/> <corners android:radius="8px" /> </shape>点击后:
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#CCCCCC"/> <corners android:radius="8px" /> </shape></span>
上面两种效果的背景选择器:
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/log_btn_default" android:state_pressed="false"/> <item android:drawable="@drawable/log_btn_pressed" android:state_pressed="true"/> </selector></span>
2、自定义edittext
edittext默认的是一条线,一般需要边框的,如圆角、边框颜色、填充空白
有个简单的背景图利用系统自带的背景:@android:drawable/edit_background_normal或者@android:drawable/edit_background
效果图:
要嘛自定义背景:
<span style="font-size:14px;"><img src="http://img.blog.csdn.net/20150902023946099?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /> 代码: </span><pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#2191FF"/> //背景色 <corners android:radius="8px" />//圆角 <stroke //边框 android:width="2px" android:color="#1B79FF" /> <padding android:left="8dp" android:top="8dp" android:right="8dp" android:bottom="8dp"/> /填充/空白 </shape>
相关文章推荐
- 解决将Github上的项目导入到Android Studio中去
- Android回调接口简单理解
- Android平台ffmpeg的硬解库生成
- 亲测可用的android基于vlc开发的音视频播放库。
- Android中bindService的使用及Service生命周期
- Android开发中颜色的自定义方法
- Android 几种发送短信的方法
- Android问题集(六)——Android工程文件夹带红色感叹号,展开工程无任何错误标志
- android 权限管理和签名 实现静默卸载
- android 里面Canvas绘制文本的方法
- Android开发之使用pull解析XML文件
- Android开发之使用Pull解析器生成XML文件
- Android开发之SharedPreferences
- Android 5.0 SDK 一些技术问题
- FrameLayout试验总结
- Android Studio系列教程一--下载与安装
- Android问题集(五)——解决提示:The method **() is undefined for the type ***()
- Android-->EventBus 3.0新版使用说明(及其使用方法)
- Android系统权限及签名
- 被遗忘的Android mipmaps简介