如何在AndroidManifest.xml中将第三方主题引用为属性

时间:2013-12-17 16:38:33

标签: android

目前,我的AndroidManifest.xml使用了第三方主题。

的AndroidManifest.xml

<application
    ...
    android:theme="@style/Theme.JStock.Light" >

    <!-- 3rd party library with 3rd party theme -->
    <activity
        android:name="group.pals.android.lib.ui.lockpattern.LockPatternActivity"
        android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
        android:screenOrientation="user"
        android:theme="@style/Alp.Theme.Light" />

的themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.JStock.Light" parent="Theme.Sherlock.Light">
        ...
    </style>

    <style name="Theme.JStock.Dark" parent="Theme.Sherlock.Dark">
        ...
    </style>

因为,我可能会在运行时更改我的应用主题

setTheme(R.style.Theme.JStock.Light);setTheme(R.style.Theme.JStock.Dark);

我希望有类似下面的内容,以便我的Java代码不需要关注第三方主题。

的AndroidManifest.xml

<application
    ...
    android:theme="@style/Theme.JStock.Light" >

    <!-- 3rd party library with 3rd party theme -->
    <activity
        android:name="group.pals.android.lib.ui.lockpattern.LockPatternActivity"
        android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
        android:screenOrientation="user"
        android:theme="?attr/thirdPartyTheme" />

的themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.JStock.Light" parent="Theme.Sherlock.Light">
        <item name="thirdPartyTheme">@style/Alp.Theme.Light</item>
        ...
    </style>

    <style name="Theme.JStock.Dark" parent="Theme.Sherlock.Dark">
        <item name="thirdPartyTheme">@style/Alp.Theme.Dark</item>
        ...
    </style>

当然,这会导致运行时错误。我可以知道,实现目标的正确方法是什么?

0 个答案:

没有答案