Android 按钮设置边框实例

以下一Button标签为例:

这里就联系到标签<shape>,设置背景样式、边框、渐变、圆角等,各种效果的使用方法见如下代码

drawable文件夹新建一个buttonstyle.xml,内容如下

1 <?xml version="1.0" encoding="utf-8"?>
2 <shape xmlns:android="http://schemas.android.com/apk/res/android">
3     <gradient android:startColor="#c0000000"  android:endColor="#c0000000" android:angle="90" /><!--背景颜色渐变 angle为渐变角度-->
4     <solid android:color="#00ffffff" /><!-- 背景填充颜色 -->
5     <stroke android:width="3dp" android:color="#ff000000" /><!-- 描边,边框宽度、颜色 -->
6     <corners android:radius="10dp" /><!-- 边角圆弧的半径 -->
7     <padding android:left="3dp" android:top="3dp" android:right="3dp" android:bottom="3dp" /><!-- 四周留出来的空白 -->
8 </shape>  

然后在button里面引用如下:

<Button
   android:id="@+id/button"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="按钮"
   android:background="@drawable/buttonstyle" /> 

引用:http://blog.csdn.net/mj19910923/article/details/8633255

时间: 2024-08-29 17:40:25

Android 按钮设置边框实例的相关文章

Android按钮设置文字变色ColorStateList

Windows平台VC,对于不同的按钮状态,采用不同的颜色显示文字,实现起来比较复杂,一般都得自绘按钮.但是Android里面实现起来非常方便. 我们首先添加一个ColorStateList资源XML文件,XML文件保存在res/color/button_text.xml: Java代码   <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://sch

为类目(类别)添加属性,使用storyboard设置边框颜色

通常使用Category时,只能添加方法,不可添加属性.但是在使用Storyboard时我们可能会使用到keyPath,这里设置的key都需要是所设置视图的属性值,并且类型有所限制. 例如:我现在有一个按钮,我想设置成圆角,并且是紫色边框.并且我不想写代码,想通过storyboard直接设置.这样看起来很帅(其实就是一个强迫症吧,因为一直在用sb设置整个界面,但是突然出现几个样式,在sb中不可以直接设置,这种感觉很烦躁的,所以要解决掉它). 遇到的问题:这里key path 的type类型是固定

Android表格布局之设置边框

Android表格布局本身没有边框,不过可以通过背景色的设置可以实现表格边框的显示. 首先可以设置TableRow的背景色,然后设置内容的背景色.根据它们的颜色差就出现了边框.只要微调Content与TableRow的margin和pading属性就可以了! 调的过程真是烦人!下次不做这种工作了~呜呜!难受! 贴上布局代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml

Android开发,使用背景图(xml drawable)为view 设置边框

Android 开发中,遇到需要设置边框的情景,使用背景图来实现,代码如下: <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 连框颜色值 --> <item> <shape> <solid android:color="#CCCCCC" /> </shape> </item>

Android中设置半个屏幕大小且居中的按钮布局 (layout_weight属性)

先看如下布局 : 上图中,按钮的大小为屏幕的一半,然后居中显示在布局中央,每个人心中都有自己的答案,看看我的方法吧,布局布局xml如下 : <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_layout&

改变Android按钮背景颜色的高效方法

本文将介绍一种有效改变Android按钮颜色的方法. 按钮可以在状态改变时改变其颜色(例如按下,禁用,高亮显示).但是,这需要一一说明每个状态.这篇文章将提供你一个根据状态变化轻松改变按钮颜色的方法.如果你正在写自定义视图,那么不妨也来读一读,因为中间我会涉及到如何用自定义属性实现自定义视图的相关内容. 如何实现 Android提供了灵活的绘制选择机制,可根据视图状态转变视图外观.每个状态通过一个单独的部分而存在.例如:在正常.禁用.按下.高亮状态下的按钮有着不同的背景颜色.请看下面的代码示例:

android TextView加边框

为TextView加边框,需要在drawable建xml文件,里面设置shape来设置文本框的特殊效果. <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 实心 --> <solid android:color="@andr

android 按钮点击事件

<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:paddingBo

【FastDev4Android框架开发】RecyclerView完全解析之结合AA(Android Annotations)注入框架实例(三十)

(一).前言: 话说RecyclerView已经面市很久,也在很多应用中得到广泛的使用,在整个开发者圈子里面也拥有很不错的口碑,那说明RecyclerView拥有比ListView,GridView之类控件有很多的优点,例如:数据绑定,Item View创建,View的回收以及重用等机制.本系列文章会包括到以下三个部分: RecyclerView控件的基本使用,包括基础,进阶,高级部分,动画之类(点击进入) RecyclerView控件的实战实例(点击进入) RecyclerView控件集合AA