开发者

Copy theme from another application

I have an application that contains a custom theme and I wish to share it with other applications. The idea is that this application provides themes to 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 theme from the second app:

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

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

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.

Does anyone know how to copy a theme from the resources of other application?? The theme won't use resources like images, etc... only values.

Thanks ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜