I have a tablet application which I am rebranding so there are multiple themes, based on the type of user.
I'd like to find the name of the theme that is currently being applied, and based on that theme then I can do some back-end functionality changes.
I have to dynamically set some image resources, which is fine as long as I pass in the correct theme resource (the R.style.redtheme), but I'd like to set this dynamically.
TypedArray a = getTheme().obtainStyledAttributes(R.style.redtheme, new int[] {aTabResource.mDrawableAttrId});
To do the styling I'm creating custom attributes and then overriding them in the styles.
If there is no simple way to get the theme, I will just save a preference.
The package manager has access to quite a bit of metadata.
It can be accessed like this:
int theme = 0; //0==not set
try
{
String packageName = getClass().getPackage().getName();
PackageInfo packageInfo = getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
theme = packageInfo.applicationInfo.theme;
}
catch (Exception e)
{
e.printStackTrace();
}
After this runs, theme will have the style resource.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With