我正在使用AppCompat Library。 在values / styles.xml中我使用以下代码
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle" tools:ignore="NewApi">@style/CLActionBar</item>
<item name="actionBarStyle">@style/CLActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="CLActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">@color/actionbar_bg_color</item>
<item name="android:textColor" tools:ignore="NewApi">@color/actionbar_txt_color</item>
<item name="android:subtitleTextStyle" tools:ignore="NewApi">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="background" >@color/actionbar_bg_color</item>
<!--<item name="textColor" >@color/actionbar_txt_color</item>-->
<item name="subtitleTextStyle" >@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
<item name="android:textColor" tools:ignore="NewApi">@color/actionbar_txt_color</item>
<!--<item name="textColor">@color/actionbar_txt_color</item>-->
</style>
在values-v21 / styles.xml中
<!– Base application theme. –>
<style name="AppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
<!– Customize your theme here. –>
</style>
- &GT;
<item name="android:actionBarStyle" tools:ignore="NewApi">@style/CLActionBar</item>
<item name="actionBarStyle">@style/CLActionBar</item>
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
<!--<item name="android:windowContentTransitions">true</item>-->
<!--<item name="android:windowAllowEnterTransitionOverlap">true</item>-->
<!--<item name="android:windowAllowReturnTransitionOverlap">true</item>-->
<!--<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>-->
<!--<item name="android:windowSharedElementExitTransition">@android:transition/move</item>-->
</style>
<!-- ActionBar styles -->
<style name="CLActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">@color/actionbar_bg_color</item>
<item name="android:textColor" tools:ignore="NewApi">@color/actionbar_txt_color</item>
<item name="android:subtitleTextStyle" tools:ignore="NewApi">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="background" >@color/actionbar_bg_color</item>
<!--<item name="textColor" >@color/actionbar_txt_color</item>-->
<item name="subtitleTextStyle" >@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
<item name="android:textColor" tools:ignore="NewApi">@color/actionbar_txt_color</item>
<!--<item name="textColor">@color/actionbar_txt_color</item>-->
</style>
现在,当我尝试使用getSupportActionBar.setTitle将标题设置为操作栏时,标题不会出现。 请帮忙
答案 0 :(得分:1)
我解决了这个问题 我使用Theme.AppCompat.Light作为应用主题和@android:style / Widget.Holo.Light.ActionBar.Solid.Inverse&#34;作为动作栏主题。将此更改为 @ style / Widget.AppCompat.Light.ActionBar.Solid.Inverse并解决了问题。 感谢
答案 1 :(得分:0)
将以下行粘贴到值文件夹
<style name="MYBaseTheame" parent="@style/Theme.AppCompat.Light">
<item name="actionBarStyle">@style/Widget.MYTheame.ActionBar</item>
</style>
<style name="MYTheame" parent="@style/MYBaseTheame">
<item name="android:windowBackground">@color/app_bg</item>
<item name="android:tabWidgetStyle">@android:style/Widget.TabWidget</item>
</style>
<style name="MYTheame.NoTittle" parent="@style/MYTheame">
<item name="android:windowNoTitle">true</item>
</style>
<style name="Widget.MYTheame.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="titleTextStyle">@style/TextAppearance.MYTheame.Widget.ActionBar.Title</item>
<item name="background">@color/ab_bg</item>
</style>
并将以下行粘贴到value-14文件夹
<style name="MYBaseTheame" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/Widget.MYTheame.ActionBar</item>
</style>
<style name="Widget.MYTheame.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:titleTextStyle">@style/TextAppearance.MYTheame.Widget.ActionBar.Title</item>
<item name="android:background">@color/ab_bg</item>
</style>