使ActionBar标题大写 [英] Make ActionBar title uppercase
问题描述
如何使ActionBar标题大写?一些答案建议将< item name ="android:textAllCaps"> true</item>
放进去,但是当我将它放在actionBar样式或actionBar的 titleTextStyle
.只有当我采用AppTheme样式时,它才会起作用,但是在我不需要的所有大写字母中,这也会在我的应用程序中产生很多问题.
How do I make the ActionBar title uppercase? Some answers suggest putting <item name="android:textAllCaps">true</item>
but this has no effect when I put it in the actionBar style or actionBar's titleTextStyle
. It only has an effect when I put in in the AppTheme style but that makes a bunch of things in my app also in all caps which I don't want.
我的风格:
<style name="AppTheme" parent="AppBaseTheme">
<!-- snip snip -->
<item name="android:actionBarStyle">@style/NewActionBar</item>
</style>
<style name="NewActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@color/text_pink</item> <!-- no effect -->
<item name="android:titleTextStyle">@style/NewActionBarTitle</item>
<item name="android:displayOptions">showHome|showTitle</item>
<item name="android:textAllCaps">true</item> <!-- no effect -->
</style>
<style name="NewActionBarTitle">
<item name="android:textSize">@dimen/tiny_text_size</item> <!-- no effect -->
<item name="android:textAllCaps">true</item> <!-- no effect -->
</style>
为什么无论我放入什么内容, NewActionBar
和 NewActionBarTitle
样式都无效?我的样式或操作栏有问题吗?
And why do the NewActionBar
and NewActionBarTitle
styles appear to have no effect no matter what I put in them? Is there something wrong with my styles or my action bar or what?
我刚刚完全删除了样式 NewActionBar
和 NewActionBarTitle
(以及在 AppTheme
样式中对它们的引用)和动作栏看起来完全一样.所以有些东西坏了.会是什么?
I've just deleted entirely the styles NewActionBar
and NewActionBarTitle
(and the reference to them in the AppTheme
style) and the action bar looks completely the same. So something is broken. What could it be?
推荐答案
您需要在操作栏标题而非操作栏的文本外观上设置 android:textAllCaps ="true"
自己设置样式或根据您的基本活动主题设置样式.
You need to set android:textAllCaps="true"
on the text appearance for the action bar's title, rather than the action bar style itself or on your base activity theme.
<style name="AppTheme" parent="AppBaseTheme">
...
<item name="actionBarStyle">@style/Widget.MyApp.ActionBar.Solid</item>
</style>
<style name="Widget.MyApp.ActionBar.Solid"
parent="Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">@style/TextAppearance.MyApp.Widget.ActionBar.Title</item>
</style>
<style name="TextAppearance.MyApp.Widget.ActionBar.Title"
parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textAllCaps">true</item>
</style>
这篇关于使ActionBar标题大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!