当前位置:首页 » 安卓系统 » android按钮的样式

android按钮的样式

发布时间: 2025-01-28 06:39:01

Ⅰ 如何自定义android Button样式

在windows7操作系统Android studio中按照如下方法定义button的样式。

1、首先使用Android studio创建一个项目,项目结构如下:

Ⅱ 如何自定义android Button样式

返回博客列表
转 android自定义button样式

sumpower
发布时间: 2014/02/25 19:56

阅读: 4162

收藏: 0

点赞: 0

评论: 0
摘要
android自定义button样式

在Android开发应用中,默认的Button是由系统渲染和管理大小的。而我们看到的成功的移动应用,都是有着酷炫的外观和使用体验的。因此,我们在开发产品的时候,需要对默认按钮进行美化。在本篇里,笔者结合在应用开发中的经验,探讨一下自定义背景的按钮、自定义形状按钮的实现方法。
首先看实现效果截图:

自定义背景的按钮目前有2种方式实现,矢量和位图。

1. 矢量图形绘制的方式
矢量图形绘制的方式实现简单,适合对于按钮形状和图案要求不高的场合。步骤如下:
(a) 使用xml定义一个圆角矩形,外围轮廓线实线、内填充渐变色,xml代码如下。
view plain
//bg_alibuybutton_default.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="地址">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFEC7600" />
<corners
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
</shape>
</item>
<item android:top="1px" android:bottom="1px" android:left="1px" android:right="1px">
<shape>
<gradient
android:startColor="#FFEC7600" android:endColor="#FFFED69E"
android:type="linear" android:angle="90"
android:centerX="0.5" android:centerY="0.5" />
<corners
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
</shape>
</item>
</layer-list>
同样定义bg_alibuybutton_pressed.xml和bg_alibuybutton_selected.xml,内容相同,就是渐变颜色不同,用于按钮按下后的背景变化效果。
(b) 定义按钮按下后的效果变化描述文件drawable/bg_alibuybutton.xml,代码如下。
view plain
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="地址">
<item android:state_pressed="true"
android:drawable="@drawable/bg_alibuybutton_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/bg_alibuybutton_selected" />
<item android:drawable="@drawable/bg_alibuybutton_default" />
</selector>
(c) 在你需要的界面定义文件中,如layout/main.xml中定义一个Button控件。
view plain
<Button
android:layout_width="120dip"
android:layout_height="40dip"
android:text="矢量背景按钮" android:background="@drawable/bg_alibuybutton" />
这样,自定义背景的按钮就可以使用了,在实现onClick方法后就可以响应操作。

Ⅲ 安卓UI自定义radiobutton样式

自定义RadioButton样式分为两步:

1、自定义好样式:

打开style.xml,添加一个item

java"><stylename="RadiobuttonStyle">
<itemname="android:gravity">center</item>
<itemname="android:textSize">16sp</item>
<itemname="android:textColor">@color/text_select_color</item>
<itemname="android:button">@null</item>
<itemname="android:drawableTop">@drawable/select_rbtn_home</item>
</style>

2、在RadioButon中引用:

<RadioButton
android:id="@+id/tv_tab_home"
style="@style/RadiobuttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/tab_home"/>
热点内容
怎么把安卓手机app转到苹果手机 发布:2025-03-18 04:20:30 浏览:966
分算法适用于 发布:2025-03-18 04:17:08 浏览:626
mysql数据库连接串 发布:2025-03-18 04:15:51 浏览:13
社会脚本法定义 发布:2025-03-18 03:59:00 浏览:326
安卓扩展存储空间 发布:2025-03-18 03:57:34 浏览:10
linuxat没反应 发布:2025-03-18 03:56:51 浏览:581
怎么看是多少位编译器 发布:2025-03-18 03:47:32 浏览:660
solr索引存储 发布:2025-03-18 03:46:52 浏览:330
缝合算法 发布:2025-03-18 03:46:06 浏览:363
java遍历二维数组 发布:2025-03-18 03:36:01 浏览:411