I managed to set the textColor from a theme from another package by using 
an override of OnApplyThemeResource of the Activity:

        protected override void OnApplyThemeResource(Resources.Theme theme, 
int resId, bool first)
        {
            if (first)
            {
                var ctx = 
ApplicationContext.CreatePackageContext("[packageidentifier]", 
PackageContextFlags.Restricted);
                var srcTheme = new ContextThemeWrapper(ctx, 
[resourcenumber_in_other_package]);
                theme.SetTo(srcTheme.Theme);

                base.OnApplyThemeResource(theme, resId, first);
            }
        }

I am using Xamarin C#, so sorry for the 'different' syntactic sugar than 
you are supposed to work with. This sadly only works if the style does not 
refer to colors but having inline values for colors and then only I managed 
to get the android:textColor to work... So not very usefull actually. May 
this is a pointer for further investigation...

Regards,
Ernstjan

Op woensdag 1 augustus 2012 23:38:12 UTC+2 schreef Mor G.:
>
> Hi Richard, thanks for the reply.
>
> I have an app with light and dark themes defined in themes.xml.
> I have a setting to allow the user the select light/dark theme in the app.
> This works great.
>
> Now the themes are pretty heavy in graphics, since they define not only 
> styling but different drawables as well, so I want to offer more themes 
> like blue, green, red, etc. as external apks in Google play, like I've seen 
> many other apps have done, so a user could install a "MyApp blue theme" 
> apk, and then he'll be able to choose this theme from the main app settings.
>
> I've tried using: Resources res = pm.getResourcesForApplication(appInfo);
> Which gets the resources object of the external apk, but I can't seem to 
> get and apply the theme from it using activity.setTheme(externalTheme).
>
> I've tried using: Context themedContext = 
> activity.getApplicationContext().createPackageContext("com.myapp.blue", 
> Context.CONTEXT_IGNORE_SECURITY);
> Which gets a themed context, but again, couldn't set this theme to my 
> running activity.
>
> I've read a lot about this, but couldn't find any complete solution.
>
> Thanks,
> Mor.
>
>
> On Thursday, August 2, 2012 12:17:40 AM UTC+3, RichardC wrote:
>>
>> If it's your own application then read about library projects.
>> Otherwise unless the app you are reading resources from is available 
>> under a suitable open source licence then in my opinion what you are trying 
>> to do could be infringing copyright.
>> If the app is open source then just download it and use the resources.
>>
>> On Thursday, April 5, 2012 6:51:58 PM UTC+1, Terry wrote:
>>>
>>> I'm able to use getResourcesForApplication and getIdentifier to get the 
>>> individual resources from another application. However, when I try to call 
>>> setTheme using a remote theme.xml from another app, the references inside 
>>> theme.xml point to the app that I'm running, not pointing to the remote 
>>> application where the theme.xml is. As a result, I get a 
>>> ResourceNotFoundException inside theme.xml where I try to use the styles I 
>>> defined from the remote app. In other words, I can apply theme.xml but not 
>>> reference to the styles inside it.
>>>
>>> Moderator, please don't block this post. I googled for days and have not 
>>> found a resolution to it.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/67a57779-1d35-4e8a-92b3-09b28d896d7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to