zoukankan      html  css  js  c++  java
  • Androidbuttonshape形状资源码实现

    1、项目Src下创建drawable

    看文档Develop/API Guides/App Resources/Drawable/Shape Drawable

    单词:corners : 角  ;  gradient :梯度; solid:固定的。 stroke: 边框--能够做下划线
           Rectangle : 矩形;dash :破折号 gap:间隙。

    2、拷贝实例代码,文件命名(gradient_box.xml,以下是模版)

    <?

    xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dip"/> <gradient android:startColor="#ff0000" android:endColor="#00ff0000"/> <solid android:color="#ffffff" /> <stroke android:width="3dip" android:color="#000000" android:dashGap="5dip" android:dashWidth="5dip"/> </shape>

    3、默认状态function_greenbutton_normal.xml

    <?xml version="1.0" encoding="utf-8"?

    > <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dip"/> <solid android:color="#ffffff" /> </shape>

    4、按下去状态状态function_greenbutton_pressed.xml

    <?

    xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dip"/> <solid android:color="#22000000" /> </shape>

    5、把两个状态整合在shape_bg.xml

    <?

    xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/function_greenbutton_pressed" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/function_greenbutton_pressed" /> <!-- focused --> <item android:drawable="@drawable/function_greenbutton_normal" /> <!-- default --> </selector>

    6、并使用

    在Button框下android:background="@drawable/shape_bg"来调用。

  • 相关阅读:
    Linux配置YUM源(2020最新最详细)
    Linux系统安装Tomcat9(2020最新最详细)
    Linux系统安装JDK1.8(2020最新最详细)
    框架集项目-登录账户过期,如何回到登录主页!
    C# 以管理员方式运行程序
    C#/STM32 WAV转byte WAV数据格式
    C# base64 转 byte[]
    C# 截取屏幕图像
    emWin 学习笔记 —— 用VS2017打开emWin仿真包
    STM32 时钟配置的坑
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/6888705.html
Copyright © 2011-2022 走看看