How can I load the strings.xml dynamically? Can I put the file in a server?

前端 未结 2 577
小蘑菇
小蘑菇 2021-01-23 01:39

Why i ask this is because the size of my APK is huge. I wanna make it smaller.

There\'re lots of strings in strings.xml. Our product manager force us to support all lan

相关标签:
2条回答
  • 2021-01-23 02:26

    can I just put some languages of strings.xml locally, put others in a server, then when user launches the app, downloads the strings.xml from it dynamically according to the language of the user.

    You cannot modify resources at runtime. You are welcome to download and process XML files at runtime, and those XML files might contain strings that you want to display to the user. However, you cannot use the Android resource system to pull in those strings. You would need to write your own Java code that uses those values, including determining which translation to use for a given device (taking into account the multiple-locale support offered in Android 7.0).

    0 讨论(0)
  • 2021-01-23 02:28

    You can easily call some web-service on your application start and fetch the strings of desired/selected language in form of say JsonArray. Then parse that data to some data-model like ArrayList of string to manage in your app

    0 讨论(0)
提交回复
热议问题