How to change title bar color of action bar in Xamarin android

How to change the program caption color of a control in Xamarin android? I have tried many things on the Internet, but I just cannot find a way to do this.

I don’t want to switch to the toolbar because I don’t know the code for this, I also don’t know if the toolbar can be made similar to the one on the action bar in the code below.

This is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Support.V7.App;
using Android.Graphics.Drawables;
using Android.Graphics;

namespace actionbarTitleColor
{
    [Activity(Label = "myActivity")]
    public class myActivity : Activity
    {
        protected override void OnCreate(Bundle bundle) {

            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Rapsolie);
            ActionBar.SetHomeButtonEnabled(true);
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ColorDrawable colorDrawable = new ColorDrawable(Color.ParseColor("#00b8ff"));
            ActionBar.SetBackgroundDrawable(colorDrawable);

        }

        public override bool OnOptionsItemSelected(IMenuItem item) {

            switch (item.ItemId) {
                case Android.Resource.Id.Home:
                    Finish();
                    return true;

                default:
                    return base.OnOptionsItemSelected(item);
            }
        }
    }
}
+4
source share
1 answer

The easiest way is to customize the style for ActionBar, for example, as follows:

<resources>
  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
  </style>

  <style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
  </style>

  <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#f08080</item>
  </style>
</resources>

Then apply this style on your page as follows:

[Activity(Label = "YOURPACKAGENAME", MainLauncher = true, Icon = "@drawable/icon", Theme = "@style/MyTheme")]

ActionBar, .

, , , , .

, Toolbar , android 5.0, , Toolbar, Toolbar.

+4

Source: https://habr.com/ru/post/1666261/


All Articles