Android 如何自定义actionbar操作项?
预期: 但操作项显示为大写文本: 我试着玩弄各种风格,但没有成功。这里有一个版本:Android 如何自定义actionbar操作项?,android,android-actionbar,Android,Android Actionbar,预期: 但操作项显示为大写文本: 我试着玩弄各种风格,但没有成功。这里有一个版本: @android:彩色/白色 @android:彩色/白色 假的 没有一个 真的 @样式/动作按钮 @样式/文本 @样式/动作菜单 假的 假的 假的 假的 菜单: 布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
@android:彩色/白色
@android:彩色/白色
假的
没有一个
真的
@样式/动作按钮
@样式/文本
@样式/动作菜单
假的
假的
假的
假的
菜单:
布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:background="@android:color/darker_gray"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.Toolbar>
</LinearLayout>
谁知道应该更改什么属性才能得到所需的结果呢?您可以尝试这种方法,为菜单标题创建一个文本布局:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_item"
app:actionLayout="@layout/action_title"
app:showAsAction="always" />
</menu>
现在,
action title
应该显示您所提供的内容Android将其中的任何文本转换为大写字母,不能更改。但如果你想要小字母,那么手动创建一个与ActionBar背景颜色相同的文本图像。你能确认这是否有效吗?这太奇怪了!我一整天都在努力让actionLayout正常工作,但绝对不能在Nexus5上运行棒棒糖。菜单项只显示为文本,我绝对不能让它尊重布局!我将在几天内发布我的代码的简化版本。是的,我的应用程序使用这种方式,工作正常。希望看到你的代码我上传了一个新的项目,在这里重新说明了我的问题:到底是什么原因导致了开关没有出现?我知道在成功使用工具栏之前我已经做过了。PEBCAK!我通过将android:actionLayout更改为app:actionLayout解决了我的问题。你没有从我的回答中看出这一点吗?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:background="@android:color/darker_gray"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.Toolbar>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_item"
app:actionLayout="@layout/action_title"
app:showAsAction="always" />
</menu>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/action_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="action item"
android:textSize="10sp"
android:textColor="@color/black"
/>
</LinearLayout>