本文实例总结了Android开发之资源文件用法。分享给大家供大家参考,具体如下:
这里记录在Android开发中经常用到的一些用法
arrays.xml定义数组
例:
1
2
3
4
5
6
7
|
< resources >
<!-- share items -->
< string-array name = "app_share_items" >
< item >新浪微博</ item >
< item >腾讯微博</ item >
</ string-array >
</ resources >
|
纯色圆角背景
1
2
3
4
|
< shape xmlns:android = "http://schemas.android.com/apk/res/android" >
< solid android:color = "#4a90e2" />
< corners android:radius = "95dp" />
</ shape >
|
用法:
1
|
android:background="@drawable/xml_background_button_blue"
|
要获取这种背景所对应的类型为:Drawable:GradientDrawable,我们可以改变它的颜色,而保持背景不变。
颜色相关
ps中:0透明,1完全不透
android:颜色格式:argb alpha:[0,255] 完全透明到完全不透明
粉红:#8f0f
uses-permission
弹窗口时,在Manifest中添加:
1
|
< uses-permission android:name = "android.permission.SYSTEM_ALERT_WINDOW" />
|
资源文件与类的对应关系
selector对应的是StateList
1
2
3
4
5
|
<? 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 >
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<? 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
1
2
3
4
5
|
<? 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常量:
1
|
public static final String DOWNLOAD_MANAGER = "com.james.app.download" ;
|
step2:在对应的Activity中指定对应的IntentFilter
1
2
3
4
|
< intent-filter >
< action android:name = "com.james.app.download" />
< category android:name = "android.intent.category.DEFAULT" />
</ intent-filter >
|
2. Notification是通过Action来区别的,不是通过ID来区别的
希望本文所述对大家Android程序设计有所帮助。