Android开发之资源文件用法实例总结
作者:bigconvience 时间:2023-05-13 06:02:39
本文实例总结了Android开发之资源文件用法。分享给大家供大家参考,具体如下:
这里记录在Android开发中经常用到的一些用法
arrays.xml定义数组
例:
<resources>
<!-- share items -->
<string-array name="app_share_items">
<item>新浪微博</item>
<item>腾讯微博</item>
</string-array>
</resources>
纯色圆角背景
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#4a90e2" />
<corners android:radius="95dp" />
</shape>
用法:
android:background="@drawable/xml_background_button_blue"
要获取这种背景所对应的类型为:Drawable:GradientDrawable,我们可以改变它的颜色,而保持背景不变。
颜色相关
ps中:0透明,1完全不透
android:颜色格式:argb alpha:[0,255] 完全透明到完全不透明
粉红:#8f0f
uses-permission
弹窗口时,在Manifest中添加:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
资源文件与类的对应关系
selector对应的是StateList
<?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/xml_login_button_press"/>
<item android:drawable="@drawable/xml_login_button_normal"/>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="@color/pressed_color"/>
</shape>
</item>
<item>
<shape>
<solid android:color="@color/transparent"/>
</shape>
</item>
</selector>
shape 对应的是GradientDrawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#4a90e2" />
<corners android:radius="95dp" />
</shape>
Notification
1. Action与Activity关联
以下两步缺一不可
step1: 指定一个Action常量:
public static final String DOWNLOAD_MANAGER = "com.james.app.download";
step2:在对应的Activity中指定对应的IntentFilter
<intent-filter>
<action android:name="com.james.app.download"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
2. Notification是通过Action来区别的,不是通过ID来区别的
希望本文所述对大家Android程序设计有所帮助。
标签:Android,资源文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android依赖注入框架Dagger2的使用方法
2021-12-19 20:25:39
![](https://img.aspxhome.com/file/2023/9/111729_0s.png)
Eclipse最新版使用过程中遇到的问题总结
2023-12-03 04:14:14
![](https://img.aspxhome.com/file/2023/0/82320_0s.png)
Java算法之递归算法计算阶乘
2021-06-30 14:10:56
![](https://img.aspxhome.com/file/2023/4/63454_0s.png)
JVM的基本介绍以及垃圾回收
2023-12-20 02:59:51
![](https://img.aspxhome.com/file/2023/1/97971_0s.jpg)
IDEA高效使用设置指南
2023-10-30 01:39:37
![](https://img.aspxhome.com/file/2023/7/108377_0s.jpg)
详解Java枚举为什么是单例模式的最佳选择
2022-07-16 20:42:47
详解Android如何实现阴影效果
2022-04-14 13:11:16
![](https://img.aspxhome.com/file/2023/0/139430_0s.png)
springboot前端传参date类型后台处理的方式
2023-04-12 16:47:35
![](https://img.aspxhome.com/file/2023/1/85941_0s.png)
SpringBoot对Controller进行单元测试的实现代码 附乱码解决方案
2021-11-26 17:57:22
![](https://img.aspxhome.com/file/2023/7/88137_0s.png)
SpringBoot多环境开发与日志小结
2021-09-18 19:05:44
![](https://img.aspxhome.com/file/2023/9/78919_0s.png)
Android手机卫士之设置密码对话框
2021-08-03 07:24:27
![](https://img.aspxhome.com/file/2023/2/100652_0s.jpg)
VS2019打包WPF安装程序最新教程(图文详解)
2021-11-18 15:52:08
![](https://img.aspxhome.com/file/2023/8/81098_0s.jpg)
C# 获取PDF中的数字签名证书
2023-03-07 18:16:15
![](https://img.aspxhome.com/file/2023/8/113878_0s.png)
c# 反射用法及效率对比
2022-06-11 17:50:19
![](https://img.aspxhome.com/file/2023/2/88322_0s.png)
详解Spring-Boot集成Spring session并存入redis
2021-10-13 07:48:30
![](https://img.aspxhome.com/file/2023/8/115888_0s.jpg)
java实现扫雷游戏入门程序
2023-04-24 16:20:40
![](https://img.aspxhome.com/file/2023/6/86786_0s.jpg)
详解spring boot引入外部jar包的坑
2021-07-29 10:49:49
![](https://img.aspxhome.com/file/2023/4/61314_0s.jpg)
spring boot 配置动态刷新详解
2023-09-26 10:24:42
![](https://img.aspxhome.com/file/2023/6/129276_0s.png)
Java将Date日期类型字段转换成json字符串的方法
2023-02-18 19:57:09
![](https://img.aspxhome.com/file/2023/0/61290_0s.png)
C#实现Check Password和锁定输错密码锁定账户功能
2023-01-20 03:04:33