Android: using XML layout from internal storage

Stackoverflow helped me a lot with my projects. Thank you for that. Now here is my problem:

I made an application for the company. This company has many customers who will use the application. The company would like to customize the layout of the application for each client. They would like, by the way, to change the background color of elements and button images.

Now I would like to:

  • download customized xml layout from their server
  • upload customized button images, etc.

(Both of them are currently loading from resources.) Then:

  • Use the ones to style the app.

Thus, downloading will not be a problem. Saving data to internal storage will also not be a problem. But.

How do I tell the application to use a custom xml layout that can be found in the internal storage? So far I have used this.

setContentView(R.layout.activity_main); 

Now I want to install the same, but based on the XML found in the internal storage.

In addition, I would like to upload images for buttons, etc. from internal storage, not from resources. Now I use this:

 findViewById(R.id.button_x).setBackgroundResource(R.drawable.button02); 

So, in a word, my question is:

Is there a way to achieve the functionality of the above code, but with files from internal storage?

+4
source share
1 answer

perhaps you can create an XmlPullParser from the file you uploaded, inflate it through the XmlPullParser obect, and pass it as a parameter to setContentView . doc for XmlPullParser here . The inflation method you should use is here . I've never tried, but theoretically seems possible

Edit:

The @RoundSparrowhilltx project can be found here

+2
source

Source: https://habr.com/ru/post/1488835/


All Articles