Android中简单的Button设计

有时候在Android中系统给的Button不好看,比较呆板,就会自己来设计一种Button,下面提供一种在drawable中自定义的xml文件来作为Button的背                                   

c,xml                                                                                                                                                                                                                                                                                                          
<strong><span style="color:#009900;BACKGROUND-COLOR: #ffffff"><?xml version="1.0" encoding="utf-8"?>
<!-- 个人理解selector为选择器,且必须要有item做子标签 -->
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- state_pressed此属性设置为true表示点了按钮之后的背景 -->
<item  android:state_pressed="true">
<shape>
    <!-- 圆角 -->
    <corners
        android:radius="10dp"/>
    <!-- 按钮的颜色 -->
    <solid
        android:color="#00FF00"/>
    </shape>
    </item>
    <!-- 默认背景 -->
    <item >
    <shape>
        <corners
            android:radius="10dp"/>
        <solid
            android:color="#0000FF"/>
        </shape>    
        
       </item>
        
</selector></span></strong>
 main.xml                                                                                                                                                                                                                                                                                                   
<strong><span style="color:#009900;BACKGROUND-COLOR: #ffffff"><RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="148dp"
        android:background="@drawable/c"
        android:text="Button" />

</RelativeLayout>
</span></strong>

当点击按钮的时候就可以看到效果,点击时按钮会变成绿色,松开时又变回蓝色
 第一次发帖,有什么不好的地方慢慢学习                                                                                                                                                                                                                      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值