B3nedikt / restring

Restring is a android library to replace string resources dynamically
Apache License 2.0
314 stars 30 forks source link

attributes.getText() not work #99

Closed TheMandalorianHub closed 2 years ago

TheMandalorianHub commented 2 years ago

the customer view to get the string resource is not work. just like:

` class MineListItemView{ ....

private fun initSetting() { val attributes = context.obtainStyledAttributes(attributeSet, R.styleable.MineListItemView) val size = attributes.indexCount for (i in 0..size) { when (val attr = attributes.getIndex(i)) { // R.styleable.MineListItemView_titleText -> { //the result is local string.xml,not the set string resource tv_title.text = attributes.getText(attr) } } } `

B3nedikt commented 2 years ago

@TheMandalorianHub The issue here is that you use obtainStyledAttributes(...) directly, this method will only work with compiled XML files, so replacing them dynamically is not possible. You can normally work around this though, but I would need a bit more input here to give some advice ;) If you want you can create a fork of this repository and modify the sample app so it reconstructs the issue. Does this help you?