一般安卓里的普通按钮控件灰灰的,比较单调,我们可以给按钮加上背景图片,或者自定义按钮的圆角,颜色等属性。

下面用代码举例:

<Button
android:id="@+id/reset"
android:layout_marginRight="2dp"
android:background="@drawable/btn_blue_selector"
android:textColor="#FFFFFFFF"
android:minWidth="120dp"
android:minHeight="32dp"
android:text="重置"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/start"
android:layout_marginRight="2dp"
android:background="@drawable/btn_blue_selector"
android:textColor="#FFFFFFFF"
android:minWidth="120dp"
android:minHeight="32dp"
android:text="开始"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
这里我自定义了btn_blue_selector.在res/drawable下新建一个Drawable resource file,命名为btn_blue_selector:

编写btn_blue_selector.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_blue_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/btn_blue_normal"/>
</selector>
当按钮按下的时候,显示的是btn_blue_press形状,没有按下的时候,是btn_blue_normal形状。分别编写对应的xml文件就好:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ff0099cc"/>
<corners android:bottomLeftRadius="16dp"
android:bottomRightRadius="16dp"
android:topLeftRadius="16dp"
android:topRightRadius="16dp"/>
</shape>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ff33b5e5"/>
<corners android:bottomLeftRadius="16dp"
android:bottomRightRadius="16dp"
android:topLeftRadius="16dp"
android:topRightRadius="16dp"/>

</shape>
---------------------

Android—修改button属性的更多相关文章

  1. Android——修改Button样式,动态修改Button中的图片大小

    原文地址: http://www.cnblogs.com/gzggyy/archive/2013/05/17/3083218.html http://www.xuebuyuan.com/2173740 ...

  2. android线程 Handler Message Queue AsyncTask线程模型 线程交互 + 修改Button样式 示例 最终easy整合版

     首先原谅我把文章的标题写的这么长.其实我还嫌弃它短了因为 写不下去了所以我就不写了.因为我实在不知道该怎么定义这篇文章的标题或许应该叫 "乱谈"比较合适. 这样可能还体现了 ...

  3. android Button 属性

    Android中button 继承了TextView组件. 可以这么用: final TextView tv = new Button(getApplicationContext()); tv.set ...

  4. Android控件属性大全(转)

    http://blog.csdn.net/pku_android/article/details/7365685 LinearLayout         线性布局        子元素任意: Tab ...

  5. android 修改系统的dialog样式

    android 修改系统的dialog样式 一.觉得自定义配置文件麻烦?那就来修改系统自定义XML文件来实现修改系统dialog的样式吧. 如果是在XML中样式:首先来说下样式.  在 Style.x ...

  6. Android(java)学习笔记263:Android下的属性动画(Property Animation)

    1. 属性动画(Property Animation)引入: 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系统在一开始的时候就给我们提供了两种实现动画效果的方式,逐帧动画(fra ...

  7. Android控件属性大全[整理转载]

    控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或falseandroid:layout_ ...

  8. Android(java)学习笔记207:Android下的属性动画(Property Animation)

    1. 属性动画(Property Animation)引入: 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系统在一开始的时候就给我们提供了两种实现动画效果的方式,逐帧动画(fra ...

  9. 【转载】Android控件属性大全

    控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或falseandroid:layout_ ...

随机推荐

  1. linux中man手冊的高级使用方法

    Linux提供了丰富的帮助手冊.当你须要查看某个命令的參数时不必到处上网查找.仅仅要man一下就可以. Linux 的man手冊共同拥有下面几个章节: 1.Standard commands (标准命 ...

  2. poj-1635 Subway tree systems(推断两个有根树是否同构)-哈希法

    Description Some major cities have subway systems in the form of a tree, i.e. between any pair of st ...

  3. HDU 4249 A Famous Equation(数位DP)

    题目链接:点击打开链接 思路:用d[i][a][b][c][is]表示当前到了第i位, 三个数的i位各自是a,b,c, 是否有进位 , 的方法数. 细节參见代码: #include<cstdio ...

  4. 打造atom成为golang开发神器

    在我在Windows系统上开发的日子里.我使用IDE开发数年之久.比如Visual Basic IDE, Borland Delphi IDE, Visual C++ 和最后的Visual Studi ...

  5. 运行Java -jar somefile.jar时发生了什么(二)

    (6)Java.c中的LoadMainClass 位置jdk/src/share/bin/java.c 该方法负责载入main函数所在的类. 该方法首先载入sun.launcher.LauncherH ...

  6. linux 磁盘性能监控

    linux下对于查看进程的命令非常多也非常强大.经常使用的如:ps  top 可是在磁盘性能监控方面就没有那么统一了. 以下列举一些磁盘监控命令.此处仅仅是起到抛砖引玉作用,具体使用參数请參考man手 ...

  7. apache ua Custom Log Formats

    RewriteEngine OnRewriteBase / RewriteCond %{HTTP_USER_AGENT} (android|bb\d+|meego).+mobile|avantgo|b ...

  8. football statistics

    https://www.whoscored.com/Players/24328/Show/Edinson-Cavani

  9. maven使用(转载)

    一.安装配置: 1.安装配置JDK    java/javac -version 2.安装配置maven   mvn -v 3.下载项目模板    mvn archetype:generate 二.详 ...

  10. C#在WinForm中使用WebKit传递js对象实现与网页交互的方法

    这篇文章主要介绍了C#在WinForm中使用WebKit传递js对象实现与网页交互的方法,涉及针对WebBroswer控件及WebKit控件的相关使用技巧,需要的朋友可以参考下 本文实例讲述了C#在W ...