ResourcesUtils.java
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.share.mvpsdk.utils;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.view.View;
/**
* Created by Horrarndoo on 2017/9/1.
* <p>
* 资源工具类-加载资源文件
*/
public class ResourcesUtils {
/**
* 获取strings.xml资源文件字符串
*
* @param id 资源文件id
* @return 资源文件对应字符串
*/
public static String getString(int id) {
return AppUtils.getContext().getResources().getString(id);
}
/**
* 获取strings.xml资源文件字符串数组
*
* @param id 资源文件id
* @return 资源文件对应字符串数组
*/
public static String[] getStringArray(int id) {
return AppUtils.getContext().getResources().getStringArray(id);
}
/**
* 获取drawable资源文件图片
*
* @param id 资源文件id
* @return 资源文件对应图片
*/
public static Drawable getDrawable(int id) {
return AppUtils.getContext().getResources().getDrawable(id);
}
/**
* 获取colors.xml资源文件颜色
*
* @param id 资源文件id
* @return 资源文件对应颜色值
*/
public static int getColor(int id) {
return AppUtils.getContext().getResources().getColor(id);
}
/**
* 获取颜色的状态选择器
*
* @param id 资源文件id
* @return 资源文件对应颜色状态
*/
public static ColorStateList getColorStateList(int id) {
return AppUtils.getContext().getResources().getColorStateList(id);
}
/**
* 获取dimens资源文件中具体像素值
*
* @param id 资源文件id
* @return 资源文件对应像素值
*/
public static int getDimen(int id) {
return AppUtils.getContext().getResources().getDimensionPixelSize(id);// 返回具体像素值
}
/**
* 加载布局文件
*
* @param id 布局文件id
* @return 布局view
*/
public static View inflate(int id) {
return View.inflate(AppUtils.getContext(), id, null);
}
}