Xamarin Forms Android AppCompatActivity工具栏的背景颜色未更改 [英] Xamarin Forms Android AppCompatActivity Toolbar background color is not changing

查看:304
本文介绍了Xamarin Forms Android AppCompatActivity工具栏的背景颜色未更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我需要更改工具栏 标题颜色背景色我尝试了Google建议的许多解决方法,但很遗憾,我找不到适合我的正确解决方案

In my Xamarin Forms Android Project I need to change the ToolBar Title color and background color I have tried with many workarounds suggested in Google but unfortunately I am unable to find the correct solution to me

我需要的是

我得到的现在是

使用以下代码

MainActivity.cs

[Activity(Label = "Sample.Droid", Icon = "@mipmap/icon_launcher", Theme = "@style/MyTheme")]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);

                global::Xamarin.Forms.Forms.Init(this, bundle);          

                LoadApplication(new App());
            }   


    }

styles.xml

    <?xml version="1.0" encoding="UTF-8"?>
<resources>

    <style name="MyTheme" parent="MyTheme.Base">
    </style>

    <style name="MyTheme.Base" parent="Theme.AppCompat.NoActionBar"> 

        <item name="windowNoTitle">true</item>     
        <item name="windowActionBar">false</item>    
        <item name="colorPrimary">#cc66ff</item>  
        <item name="colorPrimaryDark">#1976D2</item>          
        <item name="colorAccent">#FF4081</item>  

    </style>

Toolbar.axml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#cc66ff"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

我尝试过的事情

我试图更改 Toolbar.xaml 中的 android:background ,但是它没有对此有任何影响;它总是在工具栏中显示深色背景

I have tried to change the android:background in Toolbar.xaml but it doesn't have any impact on it;it is always displaying Dark background in Toolbar

,而且我也在 MainActivity.cs 中尝试了以下代码工具栏中的标题

and also I tried with this below code too in MainActivity.cs this hides the title in the Toolbar

 var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);             
              SetSupportActionBar(toolbar);

任何人,请指导我解决此问题并使我得到所需的东西

anyone please guide me to resolve this issue and make me get what I need Thanks in advance

推荐答案

在您的应用类(PCL)中,添加以下内容以更改后退按钮的颜色:

In you app class (PCL), add these to change the back button's color:

NavigationPage naviPage =  new NavigationPage( new App13.MainPage());
MainPage = naviPage;
naviPage.BarBackgroundColor = Color.FromHex("#cc66ff");

我已经做了

I have made a demo for you.

为您提供rel = nofollow noreferrer>演示。 href = https://forums.xamarin.com/discussion/103317/change-navigation-bar-back-button-color-in-xamarin-android rel = nofollow noreferrer>此处,例如@ MarlonRibeiro说过,您可以使用 drawerArrowStyle 将后退按钮的颜色更改为白色(我在github上更新了我的项目):

From here, like @MarlonRibeiro has said, you can use drawerArrowStyle to change the back button's color to white(I have updated my project on github):

 <style name="MainTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    </style>
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
    <item name="color">#FFFFFF</item> 
</style>

这篇关于Xamarin Forms Android AppCompatActivity工具栏的背景颜色未更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆