Writing Themed Android Applications

I am writing an application on Android and want users to be able to download themes and / or create for themselves. The application will have some images by default, and any themes can be installed from Market / as other APKs or can be placed on sdcard - or everything will be all right.

I want to: - allow themes to override images in buttons - right now I have XML styles to do things like highlight when selected (for the background of the + button to combine the bg button with the actual images of the buttons) - allow themes to override the background colors and text for certain things (I don’t use styles now, but I can if it makes the task easier)

I am wondering if it is easy to override the style definitions in my application / Activity onCreate based on the configuration - I would not mind restarting the application after changing the style.

Also, if it were a different APK, how would my main APK get it - by listing the packages and filtering by package name?

Perhaps there is a good tutorial?

+6
source share
1 answer

This view is actually not supported as a standard tool on Android, so you are heading for a lot of work to build it yourself.

The first thing you need to know is Context.createPackageContext (), which allows you to create a Context for another .apk (and therefore load its resources). Then you can use this Context to upload images, etc. Please note that these resources are completely different from your own application resources, so you cannot use standard tools such as themes or such to perform a replacement. You just need to manually place the code wherever you want to download "thematic" resources that explicitly extract it from this context.

To open the available .apks (and thus the package name for use with createPackageContext ()), you can use the PackageManager tools to query the components. For example, you can say that each .apk theme will have the following:

<receiver android:name="something"> <intent-filter> <action android:name="com.mydoman.action.THEME" /> </intent-filter> </receiver> 

Now you can find all .apks with such receivers through PackageManager.queryBroadcastReceivers ():

http://developer.android.com/reference/android/content/pm/PackageManager.html#queryBroadcastReceivers (android.content.Intent, int)

To select those that have the specified intent filters, use the intent made with:

 Intent intent = new Intent("com.mydoman.action.THEME"); 
+4
source

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


All Articles