Copy theme from another application

I have an application that contains a custom theme and I want to share it with other applications. The idea is that this application provides themes for other applications.

The theme is defined in styles.xml as follows:

<?xml version="1.0" encoding="utf-8"?>

<resources>

<style name="Text">
    <item name="android:textColor">#00FF00</item>
    <item name="android:textColorHighlight">#FFFF9200</item>
    <item name="android:textColorHint">#FFCCFF</item>
    <item name="android:textColorLink">#5C5CFF</item>
    <item name="android:textSize">16sp</item>
    <item name="android:textStyle">normal</item>
</style>

<style name="Button">
    <item name="android:background">#FF0000</item>
    <item name="android:focusable">true</item>
    <item name="android:clickable">true</item>
    <item name="android:textAppearance">?android:attr/textAppearanceSmallInverse</item>
    <item name="android:textColor">#FFFF00</item>
    <item name="android:textSize">22dip</item>
    <item name="android:gravity">center_vertical|center_horizontal</item>
</style>

<style name="Theme.example" parent="android:Theme">
    <item name="android:background">#FF0000</item>
    <item name="android:buttonStyle">@style/Button</item>
    <item name="android:textAppearance">@style/Text</item>
</style>

</resources>

To get this topic from the second application:

Context appThemesContext = this.getApplicationContext().  
                           createPackageContext("com.appThemes", 
                                                 Context.CONTEXT_IGNORE_SECURITY);
appThemesContext.setTheme(0x7f050002); //The resid of the desired theme
this.getTheme().setTo(appThemesContext.getTheme()); //Copy the theme

The problem is that only direct attributes such as "background" are copied, link attributes like "buttonStyle" because the "setTo" method says:

Define this topic to keep the same content as the topic is different. If both of these topics belong to the same resource, they will be identical after the return of this function. If they are from different resources, in this topic only resources that they have in common will be asked.

- , ? , .. .

;)

+5

All Articles