繁体   English   中英

使自定义主题与自定义操作栏一起使用时出现的问题

[英]Issues getting custom theme to work with custom action bar

我一直在尝试让自定义主题和操作栏一起工作。 我通过经常链接的网站为他们生成了资源。 当在清单中独立设置(仅应用程序主题或仅操作栏)时,两者都可以工作,但是当一起使用时,仅在清单中明确声明的内容可以起作用。

我的清单:

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

MyActionBar的xml文件:

<style name="Theme.MyActionBar" parent="@style/MyAppTheme">

MyAppTheme的xml:

<style name="MyAppTheme" parent="@style/Theme.AppCompat">

如上所述,操作栏的样式有效,但其余主题为AppCompat默认。 当我颠倒它们的顺序时,使MyAppTheme是MyActionBar的子级,而后者是Theme.AppCompat的子级,则应用程序主题有效,但操作栏无效。

我错过了什么吗?

谢谢。

您可以将styles.xml ActionBar样式放入父主题中,如下所示:

将您的actionBarStyle属性设置为自定义主题:

<style name="MyAppTheme" parent="@style/Theme.AppCompat">
    <item name="android:actionBarStyle">@style/mActionBar</item>
    <item name="actionBarStyle">@style/mActionBar</item>
</style>

然后,在上方使用ActionBar父级的Widget主题声明此项:

<style name="mActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <!-- set your ActionBar theme -->
</style>  

您可以看到设置ActionBar的样式 ,更多示例可能会非常有用。
让我知道是否有帮助。

该站点可以为您生成styles.xml和所有适当的资源。 您还可以选择是否生成与纯Android,ActionBarSherlock或AppCompat兼容的样式器。

ActionBar样式生成器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM