Android Studio 之 用 Drawable resource file 美化 Button 样式
shape
•新建 Drawable resource file
点击 app/src/main/res 找到 drawable 文件夹,右击->New->Drawable Resource File。
•常用属性
<gradient> : 设置渐变色
- startColor : 起始颜色
- endColor : 结束颜色
- centerColor : 中间颜色
- angle : 方向角度,等于 0 时,从左到右,然后逆时针方向转,当 angle = 90 度时从下往上
- type : 设置渐变的类型
<solid android:color = "xxx"> : 设置背景颜色
<stroke android:width = "xdp" android:color="xxx"> : 设置边框的粗细,以及边框颜色
<corners android:radius="10dp"...> : 设置圆角
•gradient
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> <gradient
android:endColor="#2196F3"
android:startColor="#9C27B0" /> </shape>
•效果图
•solid
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> <solid android:color="#2196F3" /> </shape>
•效果图
•stroke
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> <solid android:color="#FCFCFC" /> <stroke
android:width="1dp"
android:color="#F44336" /> </shape>
•效果图
•corners
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> <corners android:radius="10dp" /> <size
android:width="100dp"
android:height="200dp" /> <solid android:color="#2196F3" /> </shape>
•效果图
selector
•按下按钮时出现颜色变化
首先,新建一个 drawable resource file,根目录使用 selector ;
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false">
<shape>
<corners android:radius="10dp" />
<solid android:color="#2196F3" />
</shape>
</item> <item android:state_pressed="true">
<shape>
<corners android:radius="10dp" />
<solid android:color="#9C27B0" />
</shape>
</item> </selector>
•效果图
•参考资料
Android Studio 之 用 Drawable resource file 美化 Button 样式的更多相关文章
- Android Studio 3.1.2 Device File Explorer nothing to show
Android Studio 3.1.2 Device File Explorer nothing to show 不显示 目录 ,空白 手持终端设备: Android 4.2.2 ,API1 ...
- 第六章:Reminders实验:第二部分[Learn Android Studio 汉化教程]
Learn Android Studio 汉化教程 Reminders Lab: Part 2 This chapter covers capturing user input through the ...
- Android Studio 之 RadioButton
•任务 如何通过 RadioButton 实现如图所示的界面? •基本用法 RadioButton 单选按钮,就是只能够选中一个,所以我们需要把 RadioButton 放到 RadioGroup 按 ...
- Android Studio 学习 - 程序安装
痛定思痛,从今天开始专心学习AndriodStudio.希望以此为契机,把Java学扎实.更希望自己能坚持下去,不要半途而废. 记录一些日常的工作以及碰到的问题,权当勉励自己.荀子曰:吾尝终日而思矣, ...
- 第五章:Reminders实验:第一部分[Learn Android Studio 汉化教程]
Learn Android Studio 汉化教程 By now you are familiar with the basics of creating a new project, program ...
- Android Studio之圆形按钮设计
•效果展示图 •实现方法 点击 app/src/main/res 找到 drawable 文件夹,右击->New->Drawable Resource File. 创建一个 $drawab ...
- Android Studio中Switch控件有关 thumb 和 track 用法
•任务 •属性 android:track:底部的图片(灰->绿) android:thumb:设置 Switch 上面滑动的滑块,也就是上图中的白色圆形滑块 •switch_thumb 点击 ...
- apk反编译(6)ProGuard 工具 android studio版官方教程[作用,配置,解混淆,优化示例]
ProGuard In this document Enabling ProGuard (Gradle Builds) Configuring ProGuard Examples Decoding O ...
- android studio 的部分设置
1.android studio 如何提示方法的用法 在 Eclipse中鼠标放上去就可以提示方法的用法,实际上Android Studio也可以设置的.如图 Preferences > Edi ...
随机推荐
- js debounce & throttle All In One
js debounce & throttle All In One debounce & throttle js 节流 防抖 debounce 防抖 防抖,是指一个事件触发后在单位时间 ...
- 微信小程序 UI 组件库
微信小程序 UI 组件库 Vant Weapp 需要注意的是 package.json 和 node_modules 必须在 miniprogram 目录下 $ yarn add @vant/weap ...
- infinite auto load more & infinite scroll & load more
infinite auto load more & infinite scroll & load more https://codepen.io/xgqfrms/pen/NZVvGM ...
- 11月16日NGK公链第13期官方快讯!
- PAA子公司在印度印度成立
近日PAA房产又有大动作啦!在一片期待中,印度分公司正式成立!这是集团继泰国.越南.韩国.上海.成都.中国香港.中国台湾等分公司成立之后的又一扛鼎力作,更是PAA集团全球化战略布局的重要举措. 印度分 ...
- 翻译:《实用的Python编程》01_07_Functions
目录 | 上一节 (1.6 文件) | 下一节 (2.0 处理数据) 1.7 函数 随着程序开始变大,我们会想要有条理地组织这些程序.本节简要介绍函数.库模块以及带有异常的错误处理. 自定义函数 对你 ...
- JS广度优先遍历
自己用JS实现了 广度优先遍历 第一种用了数组的高阶函数,看起来有些复杂.然后思索着从可读性上优化了一下,孰优孰劣以后分析. var list = [{ id: "ab", chi ...
- 程序员如何在VsCode上看基金?
一 我是一个程序员. 代码是我的禁锢,基金是我的自由. 打破禁锢,奔向自由,也许只差几个定投. 有人说,买基金一定要心态好,要学会风险对冲,把8成的钱全仓买基金,剩余2成买意外身亡险,基金大涨就赚,基 ...
- 微信小程序弹出框滚动穿透问题
1.在你的遮罩层最外层加 catchtouchmove="noneEnoughPeople" 里面是你的方法名2.noneEnoughPeople: function () { c ...
- LeetCode-二叉树的深度
二叉树的深度 二叉树的深度 使用递归求解二叉树的深度. 需要注意使用的临界条件. /** * 任意一个二叉树的最大深度 **/ #include<iostream> #include< ...




