Android必知必会--使用shape制作drawable素材
2024-10-09 06:31:21
前言
最近看到朋友制作的Android APP使用了极少的图片,但是图形却极其丰富,问了之后得知是使用shape绘制的,有很多优点。
下面是我整理的一些素材:
预览
下面是图片预览:
代码
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@drawable/s1"
android:padding="5dp"
android:text="@string/s1"
android:textColor="#fff"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@drawable/s2"
android:padding="5dp"
android:text="@string/s2"
android:textColor="#ff9800"
android:textSize="16sp" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:background="@drawable/s3"
android:padding="10dp"
android:scaleType="fitXY"
android:src="@drawable/lsearch" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@drawable/s4"
android:padding="5dp"
android:text="@string/s4"
android:textColor="#fff"
android:textSize="16sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@drawable/s5"
android:padding="5dp"
android:text="@string/s5"
android:textColor="#00bcd4"
android:textSize="16sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@drawable/s6"
android:padding="5dp"
android:text="@string/s6"
android:textColor="#fff"
android:textSize="16sp" />
</LinearLayout>
shape文件
绿色标签s1.xml
:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#009688" />
<corners android:radius="8dp" />
</shape>
橙色标签s2.xml
:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#00000000" />
<corners android:radius="8dp" />
<stroke android:width="1dp" android:color="#ff9800" />
</shape>
蓝色圆形按钮s3.xml
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="#aa00bcd4" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="oval">
<solid android:color="#aa00bcd4" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#00bcd4" />
</shape>
</item>
</selector>
蓝色按钮s4.xml
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#aa00bcd4" />
<corners android:radius="8dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<solid android:color="#aa00bcd4" />
<corners android:radius="8dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="#00bcd4" />
<corners android:radius="8dp" />
</shape>
</item>
</selector>
蓝色边框按钮s5.xml
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#e3e3e3" />
<corners android:radius="8dp" />
<stroke android:width="1dp" android:color="#00bcd4" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<solid android:color="#e3e3e3" />
<corners android:radius="8dp" />
<stroke android:width="1dp" android:color="#00bcd4" />
</shape>
</item>
<item>
<shape>
<solid android:color="#00000000" />
<corners android:radius="8dp" />
<stroke android:width="1dp" android:color="#00bcd4" />
</shape>
</item>
</selector>
蓝色带阴影按钮s6.xml
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item android:top="3dp">
<shape>
<solid android:color="#00bcd4" />
<corners android:radius="8dp" />
</shape>
</item>
</layer-list>
</item>
<item android:state_focused="true">
<layer-list>
<item android:top="3dp">
<shape>
<solid android:color="#00bcd4" />
<corners android:radius="8dp" />
</shape>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item>
<shape>
<solid android:color="#dddddd" />
<corners android:radius="8dp"/>
</shape>
</item>
<item android:bottom="3dp">
<shape>
<solid android:color="#00bcd4" />
<corners android:radius="8dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
参考
最新文章
- font-family字体总结
- 【SQL篇章--DATABASE/EVENTS】
- mvc导出excel 之 新
- form、iframe实现异步上传文件
- iOS-Debug
- Web知识总结
- Dedecms v5.7 最新注入分析
- SQL —— 视图
- &#39;String&#39; does not conform to protocol &#39;CollectionType&#39; Error in Swift 2.0
- Visual C++ 打印编程技术-编程基础-映射模式
- NOI2015 程序自动分析 prog
- Android中的一些小知识
- Asp.Net Core 轻松学-HttpClient的演进和避坑
- sql判断日期是否为当前季度
- H5_canvas与svg
- luogu1082 [NOIp2012]同余方程 (扩展欧几里得)
- [转]Mysql中的SQL优化与执行计划
- Three-js 创建第一个3D场景
- IDEA 开发环境中 调试Spark SQL及遇到问题解决办法
- 最小树形图(hdu4009)
热门文章
- Python List insert()方法详解
- python笔记九(迭代)
- Python3 OS 文件/目录方法
- Python3 注释
- AbstractQueuedSynchronizer 原理分析 - 独占/共享模式
- Android Design Support Library使用详解——TextInputLayout与TextInputEditText
- 整理的Java List Set Map是否有序,元素是否允许重复
- Unity3D各平台Application.xxxPath的路径
- Android源码解析——Toast
- Scala:数据类型和变量