I explain my goal of this post.
Actualy, I want to rewrite how android works basicaly, with strings in app.
At this moment, i can change dynamicaly it from rewritting the android ressources & context, but when i refer directly a string in xml ( @string/name
), the getString
function in Ressources class isnt called. But when i do pragmaticaly a getString(R.string.my_string)
in my Fragment / Activity, getString
from Ressources class is called.
Actualy, i have this and i works good only when i use getString(R.string.my_string)
:
class MyRessources(
res: Resources?,
private val context: Context?
) : Resources(res?.assets, res?.displayMetrics, res?.configuration) {
/** {@inheritDoc} */
override fun getString(id: Int): String {
var identifier = id
val entryName = getResourceEntryName(id)
context?.let {
val name = entryName.plus("__test")
identifier = getIdentifier(name, "string", getResourcePackageName(id))
if (identifier == 0) {
identifier = id
}
}
return super.getString(identifier)
}
}
There is a simple way, with not much code, to do overwrite of that @string
behavior in xml ?