Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin, how can i set an image as background on actionbar (MasterDetailpage)

i want to set an image to action bar ( headerside) of my xamarin (crossplatform) , i create a masterdatail page but header (actionbar) need to change and i want to set an image as below. could anybody hlp me. i need a simple sample about it.

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    In Android, the method is to set the background of Toolbar.axml

    <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:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    android:background="@drawable/gradient_background_drawable"
    />
    

    file gradient_background_drawable.xml

    <?xml version="1.0" encoding="utf-8" ?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
      <gradient android:type="linear"
                android:angle="270"
                android:startColor="#008B00"
                android:endColor="#9AFF9A">
      </gradient>
    </shape>
    

    Besides,remember to remove the Property relatived with Background about toolbar in file App.xaml .

    file App.xaml

    <?xml version="1.0" encoding="utf-8" ?>
    <Application xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="FormApp202011.App">
        <Application.Resources>
            <ResourceDictionary>
                <!--Global Styles  -->
                <Color x:Key="NavigationPrimary">#2196F3</Color>
                <Style TargetType="NavigationPage">
                    <Setter Property="BarTextColor" Value="Red" />
    
                </Style>
            </ResourceDictionary>
        </Application.Resources>
    </Application>
    

    Refer: https://stackoverflow.com/questions/59545362/xamarin-forms-masterdetail-page-navbar-customization/59550198#59550198

Sign In or Register to comment.