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>

•效果图

  

•参考资料

  [1]:Android drawable resource file,圆角,渐变,自定义Switch

Android Studio 之 用 Drawable resource file 美化 Button 样式的更多相关文章

  1. 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 ...

  2. 第六章:Reminders实验:第二部分[Learn Android Studio 汉化教程]

    Learn Android Studio 汉化教程 Reminders Lab: Part 2 This chapter covers capturing user input through the ...

  3. Android Studio 之 RadioButton

    •任务 如何通过 RadioButton 实现如图所示的界面? •基本用法 RadioButton 单选按钮,就是只能够选中一个,所以我们需要把 RadioButton 放到 RadioGroup 按 ...

  4. Android Studio 学习 - 程序安装

    痛定思痛,从今天开始专心学习AndriodStudio.希望以此为契机,把Java学扎实.更希望自己能坚持下去,不要半途而废. 记录一些日常的工作以及碰到的问题,权当勉励自己.荀子曰:吾尝终日而思矣, ...

  5. 第五章:Reminders实验:第一部分[Learn Android Studio 汉化教程]

    Learn Android Studio 汉化教程 By now you are familiar with the basics of creating a new project, program ...

  6. Android Studio之圆形按钮设计

    •效果展示图 •实现方法 点击 app/src/main/res 找到 drawable 文件夹,右击->New->Drawable Resource File. 创建一个 $drawab ...

  7. Android Studio中Switch控件有关 thumb 和 track 用法

    •任务 •属性 android:track:底部的图片(灰->绿) android:thumb:设置 Switch 上面滑动的滑块,也就是上图中的白色圆形滑块 •switch_thumb 点击 ...

  8. apk反编译(6)ProGuard 工具 android studio版官方教程[作用,配置,解混淆,优化示例]

    ProGuard In this document Enabling ProGuard (Gradle Builds) Configuring ProGuard Examples Decoding O ...

  9. android studio 的部分设置

    1.android studio 如何提示方法的用法 在 Eclipse中鼠标放上去就可以提示方法的用法,实际上Android Studio也可以设置的.如图 Preferences > Edi ...

随机推荐

  1. Fullscreen API All In One

    Fullscreen API All In One 全屏显示 https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API https ...

  2. how to read the system information by using the node cli tool?

    how to read the system information by using the node cli tool? node cli & get system info demos ...

  3. how to measure function performance in javascript

    how to measure function performance in javascript Performance API Performance Timeline API Navigatio ...

  4. Flutter web & Flutter

    Flutter web & Flutter Google I/O 2019 recap & GDG shanghai flutter 与 Android 原生,应用应用,性能对比, d ...

  5. taro 禁用滚动事件

    taro 禁用滚动事件 禁止 Modal 蒙层下面的页面的内容跟随滚动 https://github.com/NervJS/taro/issues/3980 https://github.com/Ne ...

  6. position: absolute; not work

    position: absolute; not work https://stackoverflow.com/questions/11928294/css-position-absolute-with ...

  7. WLAN-AC+AP射频一劳永逸的调优方式

    AP射频调优组网图 射频调优简介 射频调优的主要功能就是动态调整AP的信道和功率,可以使同一AC管理的各AP的信道和功率保持相对平衡,保证AP工作在最佳状态.WLAN网络中,AP的工作状态会受到周围环 ...

  8. Differences between Stack and Heap

    本文转载自Differences between Stack and Heap Stack vs Heap So far we have seen how to declare basic type ...

  9. [JAVA学习笔记]JAVA基本程序设计结构

    一个简单的Java应用程序 public class FirstSample { public static void main(String[] args) { System.out.println ...

  10. scala:分别使用懒汉式和饿汉式实现单例模式

    在java中,单例模式需要满足以下要求: 构造方法私有化,使得本类之外的地方不能使用构造方法new出对象 提供私有静态属性,接收单例对象 公共的.静态的getInstance方法,便于外界拿到单例对象 ...