Android中简单的Button设计

来源:互联网 发布:淘宝服装店成本 编辑:程序博客网 时间:2024/06/03 22:55

有时候在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
原创粉丝点击