|
1 | 1 | package com.blankj.utilcode.util;
|
2 | 2 |
|
| 3 | +import android.content.res.Resources; |
| 4 | + |
3 | 5 | /**
|
4 | 6 | * <pre>
|
5 | 7 | * author: Blankj
|
@@ -190,4 +192,59 @@ public static String toSBC(final String s) {
|
190 | 192 | }
|
191 | 193 | return new String(chars);
|
192 | 194 | }
|
| 195 | + |
| 196 | + /** |
| 197 | + * Return the string value associated with a particular resource ID. It |
| 198 | + * will be stripped of any styled text information. |
| 199 | + * {@more} |
| 200 | + * |
| 201 | + * @param id The desired resource identifier, as generated by the aapt |
| 202 | + * tool. This integer encodes the package, type, and resource |
| 203 | + * entry. The value 0 is an invalid identifier. |
| 204 | + * |
| 205 | + * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist. |
| 206 | + * |
| 207 | + * @return String The string data associated with the resource, |
| 208 | + * stripped of styled text information. |
| 209 | + */ |
| 210 | + public static String getString(int id) { |
| 211 | + return Utils.getApp().getResources().getString(id); |
| 212 | + } |
| 213 | + |
| 214 | + /** |
| 215 | + * Return the string value associated with a particular resource ID, |
| 216 | + * substituting the format arguments as defined in {@link java.util.Formatter} |
| 217 | + * and {@link java.lang.String#format}. It will be stripped of any styled text |
| 218 | + * information. |
| 219 | + * {@more} |
| 220 | + * |
| 221 | + * @param id The desired resource identifier, as generated by the aapt |
| 222 | + * tool. This integer encodes the package, type, and resource |
| 223 | + * entry. The value 0 is an invalid identifier. |
| 224 | + * |
| 225 | + * @param formatArgs The format arguments that will be used for substitution. |
| 226 | + * |
| 227 | + * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist. |
| 228 | + * |
| 229 | + * @return String The string data associated with the resource, |
| 230 | + * stripped of styled text information. |
| 231 | + */ |
| 232 | + public static String getString(int id, Object... formatArgs) { |
| 233 | + return Utils.getApp().getString(id, formatArgs); |
| 234 | + } |
| 235 | + |
| 236 | + /** |
| 237 | + * Return the string array associated with a particular resource ID. |
| 238 | + * |
| 239 | + * @param id The desired resource identifier, as generated by the aapt |
| 240 | + * tool. This integer encodes the package, type, and resource |
| 241 | + * entry. The value 0 is an invalid identifier. |
| 242 | + * |
| 243 | + * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist. |
| 244 | + * |
| 245 | + * @return The string array associated with the resource. |
| 246 | + */ |
| 247 | + public static String[] getStringArray(int id){ |
| 248 | + return Utils.getApp().getResources().getStringArray(id); |
| 249 | + } |
193 | 250 | }
|
0 commit comments