I’ve tried to extend Resources class, so i can override getString(int id) methode, so can do some effects to every String needed within my Activity, here i provide some my code:
public class CustomResource extends Resources {
public CustomResource(AssetManager assets, DisplayMetrics metrics, Configuration config) {
super(assets, metrics, config);
}
@Override
public String getString(int id) throws NotFoundException {
return super.getString(id) + " $$";
}
}
and in my Activity :
CustomResource customResource;
@Override
public Resources getResources() {
if (customResource == null) {
DisplayMetrics metrics = new DisplayMetrics();
super.getWindowManager().getDefaultDisplay().getMetrics(metrics);
customResource = new CustomResource(getAssets(), metrics, super.getResources().getConfiguration());
}
return customResource;
}
but there’s error shown on Runtime:
Caused by: java.lang.NullPointerException
at com.test.TestActivity.getResources(TestActivity.java:75)
and it points to:
super.getWindowManager().getDefaultDisplay().getMetrics(metrics);
Found a way:
even after adding this resources, its still doesn’t override the Strings values coming from the LayoutInflator (ex.
setContentView(R.layout.sample))