我注意到Android> = KitKat,我无法更改工具栏项目上的默认文本颜色。我可以改变的是背景颜色。我在这里使用styles.axml尝试了所有的东西。我的工具栏背景颜色为白色,文本和菜单图标必须为蓝色。在KitKat上,一切都是白色的,包括文本。 (在我的styles.axml上,我没有设置任何颜色的白色。所以我猜是默认的。)以下解决方案适用于所有其他SDK - > App.xaml
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="ffffff"/>
<Setter Property="BarTextColor" Value="#1c4d9e"/>
</Style>
- 我的工作原理 - 因为我无法使用样式.xaml实现颜色更改。 -NOTE-我只是作为一个极端的解决方案来检测SDK是否是KitKat,只是修改工具栏的背景颜色。因为文字是白色的。我的目标是更改工具栏上每个元素的颜色,而不管SDK
public void KitKat()
{
var Check = DependencyService.Get<Interfaces.ISDK>();
var a = Check.IsKitkat();
if(a == true)
{
new Setter {Property = NavigationPage.BarBackgroundColorProperty, Value = Color.DarkRed};
new Setter {Property = NavigationPage.BarTextColorProperty, Value = Color.White};
}
}
工具栏示例
<ContentPage.ToolbarItems>
<ToolbarItem Text="Help"
Order="Primary" Command="{Binding HelpCommand}" />
<ToolbarItem AutomationProperties.IsInAccessibleTree="true"
Text="Next" Order="Secondary" Command="{Binding NextCommand}" />
</ContentPage.ToolbarItems>
首先,我通过以下操作更改了Help
选项卡。
1.我在secondary_text
中添加colors.xml
项目,
<color name="secondary_text">#DC143C</color>
2.我在<item name="actionMenuTextColor">@color/secondary_text</item>
的<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
中加入style.xml
在Android 8.1和android 4.4中运行时有我的截图
Android 8.1
Android 4.4
然后,我通过以下操作更改了Next
选项卡。
styles.xml
创建了一个新的风格,有代码。 <style name="my.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#488FCE</item>
<item name="colorPrimaryDark">#488FCE</item>
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
<item name="android:textColorPrimary">#ff0000</item>
<item name="android:textColorPrimaryInverse">#ff0000</item>
</style>
这是代码,请注意是app:popupTheme="@style/my.Base"
,而不是android:popupTheme
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/my.Base"
/>
在Android 8.1和android 4.4中运行时有我的截图。
Android 8.1
Android 4.4
有我的演示,你可以参考它。 https://github.com/851265601/ToolbarItemDemo1