您的位置:首页 > 移动开发 > Android开发

android自定义exittext和button

2015-09-02 02:26 330 查看
写项目往往要自定义exittext和button

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>



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: