zoukankan      html  css  js  c++  java
  • 自定义shape文件

    1、shape文件 btn_bg.xml文件内容
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <shape xmlns:android="http://schemas.android.com/apk/res/android">
    3. <!--背景颜色-->
    4. <solid android:color="#00CCFF"/>
    5. <!--corners 圆角角度-->
    6. <corners android:radius="300dip"/>
    7. <!--padding参数
    8. 内容距离上下左右的距离
    9. -->
    10. <padding
    11. android:bottom="50dp"
    12. android:left="50dp"
    13. android:right="50dp"
    14. android:top="50dp"/>
    15. <!-- gradient的参数
    16. 1、起始颜色
    17. android:startColor="#00CCFF"
    18. 2、中间颜色
    19. android:centerColor="#00FF00"
    20. 3、结束颜色
    21. android:startColor="#00CCFF"
    22. 4、渐变角度,必须为45的整数倍
    23. android:angle="45"
    24. -->
    25. <gradient
    26. android:startColor="#00CCFF"
    27. android:centerColor="#00FF00"
    28. android:endColor="#FF777777"
    29. android:angle="45"
    30. />
    31. <!-- stroke的参数
    32. 虚线的颜色
    33. android:color="#000007"
    34. 虚线的高度
    35. android:width="1dp"
    36. 虚线之间的距离
    37. android:dashGap="10dp"
    38. 单个虚线的大小
    39. android:dashWidth="10dp"
    40. -->
    41. <stroke
    42. android:color="#000007"
    43. android:width="10dp"
    44. android:dashGap="10dp"
    45. android:dashWidth="10dp"
    46. />
    47. </shape>

    2、在布局里引用

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. xmlns:tools="http://schemas.android.com/tools"
    4. android:layout_width="match_parent"
    5. android:layout_height="match_parent"
    6. android:padding="5dp"
    7. tools:context="lpc.com.volley_demo.MainActivity">
    8. <TextView
    9. android:background="@drawable/btn_bg"
    10. android:text="我是一个粉刷匠"
    11. android:layout_width="match_parent"
    12. android:layout_height="wrap_content" />
    13. </LinearLayout>

    3、效果






  • 相关阅读:
    linux LVM详解
    Mysql SQL优化系列之——执行计划连接方式浅释
    Vue SSR常见问题、异常处理以及优化方案
    vue组件生命周期详解
    axios全局设置url公共请求头
    WebView中JS调用Android Method 遇到的坑整理
    node.js项目多环境配置
    用vue构建多页面应用
    前端系列-移动端开发踩过的一些坑
    Async:简洁优雅的异步之道
  • 原文地址:https://www.cnblogs.com/liupengcheng/p/5685498.html
Copyright © 2011-2022 走看看