提交 20fa8673 编写于 作者: B Blankj

See 11/12 log

上级 380ccc2e
package com.blankj.utilcode.util;
import android.content.res.Resources;
import android.support.annotation.ArrayRes;
import android.support.annotation.StringRes;
/**
* <pre>
......@@ -194,57 +196,45 @@ public final class StringUtils {
}
/**
* Return the string value associated with a particular resource ID. It
* will be stripped of any styled text information.
* {@more}
* Return the string value associated with a particular resource ID.
*
* @param id The desired resource identifier, as generated by the aapt
* tool. This integer encodes the package, type, and resource
* entry. The value 0 is an invalid identifier.
*
* @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
*
* @return String The string data associated with the resource,
* stripped of styled text information.
* @param id The desired resource identifier.
* @return the string value associated with a particular resource ID.
*/
public static String getString(int id) {
return Utils.getApp().getResources().getString(id);
public static String getString(@StringRes int id) {
try {
return Utils.getApp().getResources().getString(id);
} catch (Resources.NotFoundException ignore) {
return "";
}
}
/**
* Return the string value associated with a particular resource ID,
* substituting the format arguments as defined in {@link java.util.Formatter}
* and {@link java.lang.String#format}. It will be stripped of any styled text
* information.
* {@more}
*
* @param id The desired resource identifier, as generated by the aapt
* tool. This integer encodes the package, type, and resource
* entry. The value 0 is an invalid identifier.
* Return the string value associated with a particular resource ID.
*
* @param id The desired resource identifier.
* @param formatArgs The format arguments that will be used for substitution.
*
* @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
*
* @return String The string data associated with the resource,
* stripped of styled text information.
* @return the string value associated with a particular resource ID.
*/
public static String getString(int id, Object... formatArgs) {
return Utils.getApp().getString(id, formatArgs);
public static String getString(@StringRes int id, Object... formatArgs) {
try {
return Utils.getApp().getString(id, formatArgs);
} catch (Resources.NotFoundException ignore) {
return "";
}
}
/**
* Return the string array associated with a particular resource ID.
*
* @param id The desired resource identifier, as generated by the aapt
* tool. This integer encodes the package, type, and resource
* entry. The value 0 is an invalid identifier.
*
* @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
*
* @param id The desired resource identifier.
* @return The string array associated with the resource.
*/
public static String[] getStringArray(int id){
return Utils.getApp().getResources().getStringArray(id);
public static String[] getStringArray(@ArrayRes int id) {
try {
return Utils.getApp().getResources().getStringArray(id);
} catch (Resources.NotFoundException ignore) {
return new String[0];
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册