[android-developers] Re: How to set theme using resources from another application?

2016-11-15 Thread Ejay F
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.


Re: [android-developers] Re: How to set theme using resources from another application?

2012-08-02 Thread Mor G.
Ok, if I forget about using different drawables, and keep my external theme 
to modifying current's theme existing attributes only, will that be 
possible?

I've seen the method Resources.Theme.setTo(other) which has the following 
desc.:
Set this theme to hold the same contents as the theme other. If both of 
these themes are from the same Resources object, they will be identical 
after this function returns. If they are from different Resources, only the 
resources they have in common will be set in this theme.

So this method isn't very useful if the themes are from the same resource, 
so it's used when the themes are from different resources like I'm having, 
but it doesn't seem to do the trick and change a single color value 
(textColorPrimary) I'm setting in the external theme, and after calling the 
setTo method, i'm getting resourceId as 0.

Any pointers on how to properly use Theme.setTo?

Sorry for being annoying... :)


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: How to set theme using resources from another application?

2012-08-02 Thread Mor G.
Ok, if I forget about using different drawables, and keep my external theme 
to modifying current's theme existing attributes only, will that be 
possible?

I've seen the method Resources.Theme.setTo(other) which has the following 
desc.:
Set this theme to hold the same contents as the theme other. If both of 
these themes are from the same Resources object, they will be identical 
after this function returns. If they are from different Resources, only the 
resources they have in common will be set in this theme.

So this method isn't very useful if the themes are from the same resource, 
so it's used when the themes are from different resources like I'm having, 
but it doesn't seem to do the trick and change a single color value 
(textColorPrimary) I'm setting in the external theme, and after calling the 
setTo method, i'm getting resourceId as 0.

Any pointers on how to properly use Theme.setTo?

Sorry for being annoying... :)


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How to set theme using resources from another application?

2012-08-01 Thread Mor G.
I'm searching for an answer to this as well, found a few related 
stackoverflow questions, but no full answer yet:
http://stackoverflow.com/questions/8762955/android-app-way-to-develop-app-that-has-add-ons
http://stackoverflow.com/questions/6066477/hashmapstring-drawable-mdrawables
http://stackoverflow.com/questions/7037417/copy-theme-from-another-application

On Thursday, April 5, 2012 8:51:58 PM UTC+3, 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 post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How to set theme using resources from another application?

2012-08-01 Thread RichardC
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 post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How to set theme using resources from another application?

2012-08-01 Thread 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 post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: How to set theme using resources from another application?

2012-08-01 Thread Dianne Hackborn
You can't really do this by simply pointing to a theme.  The resources
object is used across the view hierarchy to load resources; to set the
theme from another apk you will need to have the resources coming from
there, but then you won't be able to access any of your own resources that
you need (like strings etc).

On Wed, Aug 1, 2012 at 2:38 PM, Mor G. gaz...@gmail.com wrote:

 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 post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: How to set theme using resources from another application?

2012-08-01 Thread Mor G.
Hi Dianne, thanks for the info.

I've seen methods like Resources.Theme.applyStyle which capable of 
overriding existing attributes with a supplied style resource-id, which 
would have been useful if I could tell it from what resource to get the 
resource-id from.
Isn't there a similar method that I can use to only override certain 
attributes in my existing applied theme?

If not, could you maybe suggest a different way to approach this problem?
There are lots of themed apps on Android, so I'm sure there's a way to do 
this.

Thanks again,
Mor.

On Thursday, August 2, 2012 12:51:30 AM UTC+3, Dianne Hackborn wrote:

 You can't really do this by simply pointing to a theme.  The resources 
 object is used across the view hierarchy to load resources; to set the 
 theme from another apk you will need to have the resources coming from 
 there, but then you won't be able to access any of your own resources that 
 you need (like strings etc).

 On Wed, Aug 1, 2012 at 2:38 PM, 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 post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: How to set theme using resources from another application?

2012-08-01 Thread Dianne Hackborn
That doesn't solve the problem, which is that you are trying to create a
mix of resources from two .apks and you can't currently do that.

I would assume these other apps are just directly loading the bitmaps from
the other .apk where they need them.

On Wed, Aug 1, 2012 at 3:11 PM, Mor G. gaz...@gmail.com wrote:

 Hi Dianne, thanks for the info.

 I've seen methods like Resources.Theme.applyStyle which capable of
 overriding existing attributes with a supplied style resource-id, which
 would have been useful if I could tell it from what resource to get the
 resource-id from.
 Isn't there a similar method that I can use to only override certain
 attributes in my existing applied theme?

 If not, could you maybe suggest a different way to approach this problem?
 There are lots of themed apps on Android, so I'm sure there's a way to do
 this.

 Thanks again,
 Mor.


 On Thursday, August 2, 2012 12:51:30 AM UTC+3, Dianne Hackborn wrote:

 You can't really do this by simply pointing to a theme.  The resources
 object is used across the view hierarchy to load resources; to set the
 theme from another apk you will need to have the resources coming from
 there, but then you won't be able to access any of your own resources that
 you need (like strings etc).

 On Wed, Aug 1, 2012 at 2:38 PM, 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 post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en