简体   繁体   English

在Android 4.0+上消失的ActionBar

[英]ActionBarDisappearing on Android 4.0+

I am currently writing an application for devices on 2.3 - 4.2+ and am having some weird, and unexpected issues. 我目前正在为2.3-4.2+上的设备编写应用程序,并且遇到了一些奇怪的意外问题。 It was working fine until and displaying on all devices before I attempted to theme it. 在尝试为其设定主题之前,它一直运行良好,直到在所有设备上显示为止。 Even with a simple style simply extending the action bar sherlock theme, there appears to be no action bar showing. 即使使用简单的样式简单地扩展了动作栏夏洛克主题,也似乎没有显示动作栏。

The setup for the styles. 样式的设置。

<style name="FrameworkRoot.Theme" parent="Theme.Sherlock.Light.DarkActionBar">
    <!-- API 11+ (compatibility) -->
    <item name="buttonBarStyle">@style/Compat.ButtonBar</item>
    <item name="buttonBarButtonStyle">@style/Compat.ButtonBarButton</item>
    <item name="indeterminateProgressStyle">@style/Compat.IndeterminateProgress</item>
    <!-- API 14+ (compatibility) -->
    <item name="listPreferredItemPaddingLeft">@dimen/compat_list_preferred_item_padding_left</item>
    <item name="listPreferredItemPaddingRight">@dimen/compat_list_preferred_item_padding_right</item>
    <item name="listPreferredItemHeightSmall">@dimen/compat_list_preferred_item_height_small</item>
</style>

<style name="Theme.Base" parent="FrameworkRoot.Theme">
    <item name="textHeaderMaxLines">@integer/text_header_max_lines</item>
    <item name="trackAbstractMaxLines">@integer/track_abstract_max_lines</item>
    <item name="activatableItemBackground">@drawable/activatable_item_background</item>
</style>    

<!-- Base themes for the app -->
<style name="Theme.TestApp" parent="Theme.Base">
    <item name="actionBarStyle">@style/Widget.TestApp.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.TestApp.ActionBar</item>
</style>

<!-- Base Action Bar Style -->
<style name="Widget.TestApp.ActionBar" parent="Theme.Sherlock.Light.DarkActionBar">

</style>

If I remove the: 如果我删除:

<item name="android:actionBarStyle">@style/Widget.TestApp.ActionBar</item>

So that the action bar itself it not getting styled in 3.0+, I can't style the bar. 为了使动作栏本身不会在3.0+中设置样式,我无法设置样式。

What would be the best way to set this up? 进行此设置的最佳方法是什么? AndroidManifest.xml is pointing the app's style at "Theme.TestApp". AndroidManifest.xml将应用程序的样式指向“ Theme.TestApp”。

My end goal is to have a custom background on the action bar, as well as custom tab selector colors and fonts. 我的最终目标是在操作栏上具有自定义背景,以及自定义选项卡选择器的颜色和字体。 What would be the best way to go about this, as my current method isn't working well. 最好的方法是什么,因为我目前的方法效果不佳。

You have to set an attribute for ActionBarSherlock and the native ActionBar. 您必须为ActionBarSherlock 本机ActionBar设置属性。 So replace this for example: 因此,例如,替换为:

<style name="Theme.Base" parent="FrameworkRoot.Theme">
    <item name="textHeaderMaxLines">@integer/text_header_max_lines</item>
    <item name="trackAbstractMaxLines">@integer/track_abstract_max_lines</item>
    <item name="activatableItemBackground">@drawable/activatable_item_background</item>
</style>    

With this: 有了这个:

<style name="Theme.Base" parent="FrameworkRoot.Theme">

    <item name="textHeaderMaxLines">@integer/text_header_max_lines</item>
    <item name="trackAbstractMaxLines">@integer/track_abstract_max_lines</item>
    <item name="activatableItemBackground">@drawable/activatable_item_background</item>

    <item name="android:textHeaderMaxLines">@integer/text_header_max_lines</item>
    <item name="android:trackAbstractMaxLines">@integer/track_abstract_max_lines</item>
    <item name="android:activatableItemBackground">@drawable/activatable_item_background</item>

</style>    

The attributes with the 'android' prefix point to the internal resources for the native ActionBar, the attributes without the 'android' in front point to the resources of the ActionBarSherlock. 带有“ android”前缀的属性指向本机ActionBar的内部资源,前面没有“ android”的属性指向ActionBarSherlock的资源。

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

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