如何使用Holo.Light主题,但ActionBar使用Holo而不使用ICS?

Tho*_*mas 15 android themes android-3.0-honeycomb android-actionbar

我想有一个黑暗的ActionBar,但让应用程序的其余部分使用Holo.Light主题.我知道在ICS/4.0中有一个Theme.Holo.Light.DarkActionBar主题,但我希望这也适用于Honeycomb/3.0 +.

在片刻我正在使用黑暗的Holo主题,而对于我的其他组件,我正在使用ContextThemeWrapper.但这是很多工作,很容易导致错误.

这可能吗?

Kar*_*som 24

创建自定义样式并将父样式设置为holo light主题,但将ActionBar设置为普通Holo.

一个像这样的xml文件应该完成这项工作(仅仅是我的记忆):

<style name="appstyle0" parent="android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@android:style/Widget.Holo.ActionBar</item>
</style>
Run Code Online (Sandbox Code Playgroud)

然后在AndroidManifest.xml中将appstyle0设置为样式,并在所有Activity中设置holo light主题但操作栏样式为holo dark.

编辑: 我检查了为什么我的第一个答案不起作用.

<style name="Widget.Holo.Light.ActionBar" parent="Widget.Holo.ActionBar">
    <item name="android:titleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Title</item>
    <item name="android:subtitleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle</item>
    <item name="android:background">@android:drawable/ab_transparent_light_holo</item>
    <item name="android:backgroundStacked">@android:drawable/ab_stacked_transparent_light_holo</item>
    <item name="android:backgroundSplit">@android:drawable/ab_bottom_transparent_light_holo</item>
    <item name="android:homeAsUpIndicator">@android:drawable/ic_ab_back_holo_light</item>
    <item name="android:progressBarStyle">@android:style/Widget.Holo.Light.ProgressBar.Horizontal</item>
    <item name="android:indeterminateProgressStyle">@android:style/Widget.Holo.Light.ProgressBar</item>
</style>
Run Code Online (Sandbox Code Playgroud)

操作栏在styles.xml中定义,其属性通常由主题设置.首先,BG是透明的,因此您应该使用"Widget.Holo.Light.ActionBar.Solid"作为父级.然后你必须将不同的项目逐个设置为黑暗主题.让我们以titleTextStyle为例:

<style name="TextAppearance.Holo.Widget.ActionBar.Title.Own"
       parent="TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@android:color/primary_text_holo_dark</item>
    <item name="android:textColorHighlight">@android:color/highlighted_text_holo_dark</item>
    <item name="android:textColorHint">@android:color/hint_foreground_holo_dark</item>
    <item name="android:textColorLink">@android:color/holo_blue_light</item>
</style>
Run Code Online (Sandbox Code Playgroud)

现在设置为.

<item name="android:titleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Title.Own</item>
Run Code Online (Sandbox Code Playgroud)

使用上面的xml属性继续这样做.

要查找所有相关属性,请在styles.xml和themes.xml中搜索参数.很抱歉告诉我,但根据我所看到的,我想根本没有简单的方法......

  • 提到的抽签不公开,你怎么坐着工作? (8认同)

kri*_*sla 5

当我想在操作栏中放置自定义视图时,我遇到了类似的问题.我想要一个黑暗的动作栏,而应用程序的其余部分仍然很轻.更具体地说,我在动作栏中有旋转器.

首先,你的主题应该扩展

<style name="MyTheme.Light" parent="android:Theme.Holo.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)

接下来,从您的活动中,将getActionBar().getThemedContext()其用作夸大视图的上下文.在我的实例中,这是我传递给我的微调器数组适配器.

为我工作完美.