Android—修改button属性
一般安卓里的普通按钮控件灰灰的,比较单调,我们可以给按钮加上背景图片,或者自定义按钮的圆角,颜色等属性。
下面用代码举例:
<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属性的更多相关文章
- Android——修改Button样式,动态修改Button中的图片大小
原文地址: http://www.cnblogs.com/gzggyy/archive/2013/05/17/3083218.html http://www.xuebuyuan.com/2173740 ...
- android线程 Handler Message Queue AsyncTask线程模型 线程交互 + 修改Button样式 示例 最终easy整合版
首先原谅我把文章的标题写的这么长.其实我还嫌弃它短了因为 写不下去了所以我就不写了.因为我实在不知道该怎么定义这篇文章的标题或许应该叫 "乱谈"比较合适. 这样可能还体现了 ...
- android Button 属性
Android中button 继承了TextView组件. 可以这么用: final TextView tv = new Button(getApplicationContext()); tv.set ...
- Android控件属性大全(转)
http://blog.csdn.net/pku_android/article/details/7365685 LinearLayout 线性布局 子元素任意: Tab ...
- android 修改系统的dialog样式
android 修改系统的dialog样式 一.觉得自定义配置文件麻烦?那就来修改系统自定义XML文件来实现修改系统dialog的样式吧. 如果是在XML中样式:首先来说下样式. 在 Style.x ...
- Android(java)学习笔记263:Android下的属性动画(Property Animation)
1. 属性动画(Property Animation)引入: 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系统在一开始的时候就给我们提供了两种实现动画效果的方式,逐帧动画(fra ...
- Android控件属性大全[整理转载]
控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或falseandroid:layout_ ...
- Android(java)学习笔记207:Android下的属性动画(Property Animation)
1. 属性动画(Property Animation)引入: 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系统在一开始的时候就给我们提供了两种实现动画效果的方式,逐帧动画(fra ...
- 【转载】Android控件属性大全
控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或falseandroid:layout_ ...
随机推荐
- 操作系统开发之——打开A20
我们在上一篇文章提到.怎样制作Bootsect.当然,人总是贪婪的,制作完Bootsect又想着做Setup了,Setup主要工作是打开A20,进入保护模式,等等. 一.介绍A20 这是一个历史性问题 ...
- 一个经典的消费者和生产者的实现(linux )
#include <stdio.h> #include <pthread.h> #define BUFFER_SIZE 16 // 缓冲区数量 struct ...
- [JavaEE] Bootstrapping a JavaEE Application
To bootsrap the application use the following Maven archetype: mvn -DarchetypeGroupId=org.codehaus.m ...
- LeetCode 21. Merge Two Sorted Lists (合并两个有序链表)
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- POJ 1741 Tree 树形DP(分治)
链接:id=1741">http://poj.org/problem?id=1741 题意:给出一棵树,节点数为N(N<=10000),给出N-1条边的两点和权值,给出数值k,问 ...
- jeasyui-datagrid使用笔记
formatter转换ID为值 设置字典缓存 var DictionaryItem = {}; $.post('/Dictionary/GetDictionary/T_RKXD', function ...
- 【总结】设备树语法及常用API函数【转】
本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74352188 一.DTS编写语法 二.常用函数 设备树函数思路是:uboot ...
- 在word中doc与docx的区别是什么(整理)
在word中doc与docx的区别是什么(整理) docx 是Office2007使用的,是用新的基于XML的压缩文件格式取代了其目前专有的默认文件格式,在传统的文件名扩展名后面添加了字母x(即.do ...
- XAML实例教程系列 - XAML传递参数到值转换类实例 八
Kevin Fan分享开发经验,记录开发点滴 XAML实例教程系列 - XAML传递参数到值转换类实例 2012-06-28 05:25 by jv9, 508 阅读, 0 评论, 收藏, 编辑 继上 ...
- SQL 字符串处理函数大全
select语句中只能使用sql函数对字段进行操作(链接sql server),select 字段1 from 表1 where 字段1.IndexOf("云")=1;这条语句不对 ...