1
I’m trying to change the background color of Toolbar Android, in a Xamarin Forms application.
Expected result:
Current Result:
Styles.xml
<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="MyTheme.Base"
parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#b71c1c</item>
<item name="android:textColorPrimary">#ffffff</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:windowBackground">@color/window_background</item>
<item name="toolbarStyle">@style/MyToolBarStyle</item>
</style>
<style name="MyToolBarStyle"
parent="Widget.AppCompat.Toolbar">
<item name="android:background">#b71c1c</item>
<item name="android:colorBackground">#b71c1c</item>
<item name="titleTextAppearance">@style/MyTitleTextAppearance</item>
<item name="subtitleTextAppearance">@style/MySubTitleTextAppearance</item>
</style>
<style name="MyTitleTextAppearance"
parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:background">#ff0000</item>
</style>
<style name="MySubTitleTextAppearance"
parent="TextAppearance.Widget.AppCompat.Toolbar.Subtitle">
<item name="android:textColor">#1976d2</item>
</style>
</resources>
Toolbar.xml
<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:theme="@style/MyToolBarStyle"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
What’s wrong I can’t identify?
You’re doing it in [tag:Xamarin.android], but the question suggests [tag:Xamarin.Forms]. You want the answer to 'What’s wrong I can’t identify?' or to 'how to do in Xamarin.Forms'?
– Diego Rafael Souza
I am not doing in Xamarin.Android. It is a project Xamarin Forms Cross Platform.
– Washington Morais
The code you are showing in the question is from the android project.
– Diego Rafael Souza
That’s right. It is the Android project that is part of the Cross Solution. To be clear I will change the question
– Washington Morais