我让这个课程扩展了资源:
public class CustomResources extends Resources {
private static CustomResources instance;
/**
* Create a new Resources object on top of an existing set of assets in an
* AssetManager.
*
* @param assets Previously created AssetManager.
* @param metrics Current display metrics to consider when
* selecting/computing resource values.
* @param config Desired device configuration to consider when
*/
public CustomResources(AssetManager assets, DisplayMetrics metrics, Configuration config) {
super(assets, metrics, config);
}
public static CustomResources getInstance(AssetManager assets, DisplayMetrics metrics, Configuration config) {
if (instance == null) {
instance = new CustomResources(assets, metrics, config);
}
return instance;
}
@Override
public String getString(int id) throws NotFoundException {
return super.getString(id) + " $$";
}
}
我通过以下方式设立了新的资源:
@Override
public Resources getResources() {
return CustomResources.getInstance(super.getAssets(), super.getResources().getDisplayMetrics(), super.getResources().getConfiguration());
}
所以,我想自定义的resurses适用于我加载的布局中包含的所有字符串:
setContentView(R.layout.at_site);
但它仅适用于由以下内容加载的字符串:
title.setText(getString(R.string.at_site_at_receiver));
我错过了什么?
答案 0 :(得分:0)
您可以使用Android内置的替代资源管理(请参阅Guide to Localization。
如果这不符合您的需求,我建议您将所有资源声明为数组,并根据用户的设置选择合适的资源。但这将是一个更复杂的解决方案。