Vla*_*mir 42 android lowercase menuitem android-actionbar
我想在ActionBar中将MenuItem标题设置为LowerCase.
我的menu.xml
<item android:id="@+id/register"
android:title="Register"
android:showAsAction="ifRoom|withText"/>
<item android:id="@+id/unregister"
android:title="Unregister"
android:showAsAction="ifRoom|withText"/>
Run Code Online (Sandbox Code Playgroud)
在ActionBar上,它看到"REGISTER"和"UNREGISTER",但我希望它看作"注册"和"取消注册".
是否可以在MenuItem上设置首字母上限和下一个字母?我怎么能这样做?
Ale*_*nov 47
本机ActionBar实现的解决方案:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Holo">
<item name="android:actionMenuTextAppearance">@style/MyMenuTextAppearance</item>
</style>
<style name="MyMenuTextAppearance" parent="android:TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
如果您使用的是ActionBarSherlock,则有两种不同的方法:
1)创建布尔资源abs__config_actionMenuItemAllCaps并将其设置为false:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="abs__config_actionMenuItemAllCaps">false</bool>
</resources>
Run Code Online (Sandbox Code Playgroud)
2)或者使用overriden创建主题actionMenuTextAppearance并在AndroidManifest.xml以下位置使用它:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="Theme.Sherlock">
<item name="actionMenuTextAppearance">@style/MyMenuTextAppearance</item>
<item name="android:actionMenuTextAppearance">@style/MyMenuTextAppearance</item>
</style>
<style name="MyMenuTextAppearance" parent="TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
请注意:ActionBarSherlock中存在错误,强制MenuItem在pre-ICS上为大写(https://github.com/JakeWharton/ActionBarSherlock/issues/969).我已提交补丁但目前尚未合并.现在你可以使用我的fork:https://github.com/alexander-mironov/ActionBarSherlock/tree/dev,当我的代码在主存储库中合并时,我将更新这个答案.
更新:我的修复程序已合并到主ActionBarSherlock存储库中.
小智 25
将以下内容添加到您的一个值xml文件中 -
<bool name="abc_config_actionMenuItemAllCaps">false</bool>
Run Code Online (Sandbox Code Playgroud)
Enr*_*man 24
只是为了完成答案,如果您使用的是AppCompat,则父样式为:
<style name="MyMenuTextAppearance" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)
Rhu*_*fer 10
为了使菜单文本像"菜单项"一样小写到"菜单项"这里是我的解决方案.
在res >> values >> styles.xml中添加以下内容:
<style name="MenuItemTextAppearance" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="textAllCaps">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)
您可以在AppTheme上调用它:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">...</item>
<item name="colorPrimaryDark">...</item>
<item name="colorAccent">...</item>
<item name="actionMenuTextAppearance">@style/MenuItemTextAppearance</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助.:)
我在这里尝试了其他一些答案,但没有运气(我没有使用操作栏夏洛克)。正如评论中提到的,在较新的支持库中,上述解决方案似乎不起作用。为了解决这个问题,我在菜单项中添加了我自己的 actionLayout。
<item
android:id="@+id/done"
app:showAsAction="always"
android:title="@string/yourTitle"/>
Run Code Online (Sandbox Code Playgroud)
然后在我的代码中我做了这样的事情。
final MenuItem done = menu.findItem(R.id.done);
done.setActionView(R.layout.menu_item_kingfisher_text_view);
TextView doneTextView = (TextView) done.getActionView();
Run Code Online (Sandbox Code Playgroud)
然后你可以用文本视图做你想做的事情,避免文本全部大写。这绝对不理想,但如果您需要解决此问题的方法,这确实有效。
| 归档时间: |
|
| 查看次数: |
19225 次 |
| 最近记录: |