在XAML中更改ToolBarItem的颜色 [英] Change color of ToolBarItem in XAML
问题描述
我在我的应用程序中添加了一个工具栏项目,但是我看不到更改其背景和文本颜色的方法.
I've added a toolbaritem in my app, however i dont see a way to change its background and text color.
<ContentPage.ToolbarItems>
<ToolbarItem Text="About"
Icon="ic_action_more_vert.png"
Priority="0"
Order="Secondary"
Clicked="ToolbarItem_Clicked"/>
<ToolbarItem Text="Settings"
Icon="ic_action_more_vert.png"
Priority="0"
Order="Secondary"/>
</ContentPage.ToolbarItems>
这就是我想要更改的内容.黑色菜单带有白色文本,想要更改该bg颜色和文本颜色.知道如何实现吗?
This is what I'd like changed. The black menu with white text, want to change that bg color and text color. Any idea how to achieve this?
推荐答案
如@Gerald Versluis所建议的,您可以通过Android样式来实现.
As @Gerald Versluis suggested, you can do this by Android styling.
首先,您可以在Android项目的Resources
的values文件夹下找到styles.xml
文件:
Firstly you can find the styles.xml
file under the values folder of Resources
in Android project:
在此文件内,您可以打开此文件并为菜单创建样式,如下所示:
Inside of this file, you can open this file and create a style for your menu like this:
<style name="AppToolbarTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:colorBackground">#2196F3</item>
<item name="android:textColor">#000080</item>
</style>
然后在android项目中打开Toolbar.axml
Then open the Toolbar.axml
in android project
并像这样更改Toolbar
的app:popupTheme
:
app:popupTheme="@style/AppToolbarTheme"
更新:
这是Toolbar
的代码:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/AppToolbarTheme" />
这篇关于在XAML中更改ToolBarItem的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!