简体   繁体   English

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

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

I've been trying to get a custom theme and action bar to work together. 我一直在尝试让自定义主题和操作栏一起工作。 I generated the resources for them with the often-linked sites. 我通过经常链接的网站为他们生成了资源。 Both work when set up independently in the manifest (only the app theme, or only the action bar), but when used together only the one explicitly stated in the manifest works. 当在清单中独立设置(仅应用程序主题或仅操作栏)时,两者都可以工作,但是当一起使用时,仅在清单中明确声明的内容可以起作用。

My manifest: 我的清单:

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

MyActionBar's xml file: MyActionBar的xml文件:

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

MyAppTheme's xml: MyAppTheme的xml:

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

As mentioned above the action bar's style works, but the rest of the theme is AppCompat default. 如上所述,操作栏的样式有效,但其余主题为AppCompat默认。 When I reverse their order, so that MyAppTheme is MyActionBar's child, and the latter is a child of Theme.AppCompat, the application theme works, but the action bar doesn't. 当我颠倒它们的顺序时,使MyAppTheme是MyActionBar的子级,而后者是Theme.AppCompat的子级,则应用程序主题有效,但操作栏无效。

Have I missed something? 我错过了什么吗?

Thanks. 谢谢。

You can put your ActionBar style into your parent Theme, in styles.xml , as follows: 您可以将styles.xml ActionBar样式放入父主题中,如下所示:

Set your actionBarStyle attribute into your Custom Theme: 将您的actionBarStyle属性设置为自定义主题:

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

Then, declare this item above with the ActionBar parent's Widget Theme: 然后,在上方使用ActionBar父级的Widget主题声明此项:

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

You can see Styling the ActionBar , it might be very useful with more examples. 您可以看到设置ActionBar的样式 ,更多示例可能会非常有用。
Let me know if this helps. 让我知道是否有帮助。

This site can generate the styles.xml and all the appropriate resources for you. 该站点可以为您生成styles.xml和所有适当的资源。 You can also choose whether to generate stylers that are compliant with pure Android, ActionBarSherlock, or AppCompat. 您还可以选择是否生成与纯Android,ActionBarSherlock或AppCompat兼容的样式器。

ActionBar Style Generator ActionBar样式生成器

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

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