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

See 11/12 log

上级 380ccc2e
package com.blankj.utilcode.util; package com.blankj.utilcode.util;
import android.content.res.Resources; import android.content.res.Resources;
import android.support.annotation.ArrayRes;
import android.support.annotation.StringRes;
/** /**
* <pre> * <pre>
...@@ -194,57 +196,45 @@ public final class StringUtils { ...@@ -194,57 +196,45 @@ public final class StringUtils {
} }
/** /**
* Return the string value associated with a particular resource ID. It * Return the string value associated with a particular resource ID.
* will be stripped of any styled text information.
* {@more}
* *
* @param id The desired resource identifier, as generated by the aapt * @param id The desired resource identifier.
* tool. This integer encodes the package, type, and resource * @return the string value associated with a particular resource ID.
* 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.
*/ */
public static String getString(int id) { public static String getString(@StringRes int id) {
return Utils.getApp().getResources().getString(id); try {
return Utils.getApp().getResources().getString(id);
} catch (Resources.NotFoundException ignore) {
return "";
}
} }
/** /**
* Return the string value associated with a particular resource ID, * 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.
* *
* @param id The desired resource identifier.
* @param formatArgs The format arguments that will be used for substitution. * @param formatArgs The format arguments that will be used for substitution.
* * @return the string value associated with a particular resource ID.
* @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.
*/ */
public static String getString(int id, Object... formatArgs) { public static String getString(@StringRes int id, Object... formatArgs) {
return Utils.getApp().getString(id, formatArgs); try {
return Utils.getApp().getString(id, formatArgs);
} catch (Resources.NotFoundException ignore) {
return "";
}
} }
/** /**
* Return the string array associated with a particular resource ID. * Return the string array associated with a particular resource ID.
* *
* @param id The desired resource identifier, as generated by the aapt * @param id The desired resource identifier.
* 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 The string array associated with the resource. * @return The string array associated with the resource.
*/ */
public static String[] getStringArray(int id){ public static String[] getStringArray(@ArrayRes int id) {
return Utils.getApp().getResources().getStringArray(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.
先完成此消息的编辑!
想要评论请 注册