android自定义exittext和button

写项目往往要自定义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="https://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>


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值