6 Replies - 300 Views - Last Post: 09 October 2018 - 06:54 PM

#1 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 24
  • View blog
  • Posts: 555
  • Joined: 29-October 16

XAMARIN: How to Change the Color of [Android] ActionBar

Posted 30 September 2018 - 01:14 PM

Hey all,
I've been looking for a few weeks to find the way I could change the color of a deprecated method in C# Xamarin for Android known as' ActionBar ' .. apparently, the devs don't want me to use it, but I like the bigger style of button on mobile. My actionbar is white and I want it to be black: does anyone know how to change the color w/Xamarin? I've seen some android studio posts but I'm missing included assembly references to use them.

When I find the answer, I will post it here for future reference. :bananaman:

Is This A Good Question/Topic? 0
  • +

Replies To: XAMARIN: How to Change the Color of [Android] ActionBar

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6763
  • View blog
  • Posts: 23,063
  • Joined: 05-May 12

Re: XAMARIN: How to Change the Color of [Android] ActionBar

Posted 30 September 2018 - 05:35 PM

Moving to Mobile Development...
Was This Post Helpful? 0
  • +
  • -

#3 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 24
  • View blog
  • Posts: 555
  • Joined: 29-October 16

Re: XAMARIN: How to Change the Color of [Android] ActionBar

Posted 05 October 2018 - 07:18 PM

So here's the code to set background color of TabHost / ActionBar in Xamarin (latest version 2018). I have been searching far and wide for this and had no answers that work with the current version of Xamarin for Android.

Check it out:

Assemblies
    
    using System;
    using Android.App;
    using Android.Content;
    using Android.Graphics.Drawables;
    using Android.OS;
    using Android.Widget;
    using Android.Webkit;


This assumes you have already done all the back code to create a complete TabHost...
if you need a sample you can download this app and edit it accordingly

https://github.com/h...bile_Android_a2

   
            TabHost tabHost = FindViewById<TabHost>(Android.Resource.Id.TabHost);

            tabHost.Setup();

            tabHost.SetBackgroundColor(Android.Graphics.Color.Black);


    


Now I'm trying to figure out how to change the foreground text color of the tabs. Stay tuned...

This post has been edited by hexagod: 06 October 2018 - 08:31 AM

Was This Post Helpful? 0
  • +
  • -

#4 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 24
  • View blog
  • Posts: 555
  • Joined: 29-October 16

Re: XAMARIN: How to Change the Color of [Android] ActionBar

Posted 08 October 2018 - 07:23 PM

=[

Finding the command to change text color is like finding jimmy hoffa's body

:gun_bandana: :withstupid:

Attached image(s)

  • Attached Image

This post has been edited by hexagod: 08 October 2018 - 07:24 PM

Was This Post Helpful? 0
  • +
  • -

#5 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 198
  • View blog
  • Posts: 1,115
  • Joined: 05-December 13

Re: XAMARIN: How to Change the Color of [Android] ActionBar

Posted 09 October 2018 - 10:07 AM

You get it from textview. You need to iterate something like... try this:
            TabHost tabhost = getTabHost();
            for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++)
            {
                TextView tv = (TextView)tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
                tv.setTextColor(Color.parseColor("#FFFFFF"));
            }

Was This Post Helpful? 0
  • +
  • -

#6 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 24
  • View blog
  • Posts: 555
  • Joined: 29-October 16

Re: XAMARIN: How to Change the Color of [Android] ActionBar

Posted 09 October 2018 - 06:22 PM

that looks overly complex and I can't find the backstory to get it working. I've seen that solution and been trying to get it working for the last week. The assembly references, back code, dated look of the code don't seem ideal.

Here's the easy solution to changing text color of TabHost / ActionBar layout in C# / XAML / Xamarin for droid

add this line into theme.xml ... replace the #XXXXXX with a hex code (or you can get creative and use dynamic references, I think?)

this one is plain yellow

    <item name="android:textColorPrimary">#FCE300</item>



this is how the theme.xml looks (in a very simple layout) so you know where it fits in context

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:textColorPrimary">#FCE300</item>
  </style>

  <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#000000</item>
  </style>
</resources>



then make sure you add this line (so your TabHost knows where it's to find the theme containing text color) into your main.axml where the TabHost xaml structure is contained

android:theme="@style/MyTheme">



and your TabHost format should look something like this

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
	android:theme="@style/MyTheme">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>



I saw a bunch of posts on this, and most are overly complex, or outdated. Some of those methods and properties don't work anymore (changes to class structure?). This will work in Xamarin 2018 Android. If you're still lost then download the BitChute app from GitHub and you can get a full idea for how to create a tabhost.

I know there's better ways to do this (dynamically) ... but these are the absolute simplest, most effective ways to change the colors of deprecated TabHost when using 2018 Android Xamarin. If you've got more to add to the conversation, I'm always open to expanding my methods.

Attached image(s)

  • Attached Image

This post has been edited by hexagod: 09 October 2018 - 06:30 PM

Was This Post Helpful? 0
  • +
  • -

#7 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 24
  • View blog
  • Posts: 555
  • Joined: 29-October 16

Re: XAMARIN: How to Change the Color of [Android] ActionBar

Posted 09 October 2018 - 06:54 PM

Hey, can the mods change this title to actionbar / TabHost ??? Technically, I'm not changing the color of the actionbar.

actionbar is getting

ActionBar.Hide();



however, actionbar and tabhost are both present in this code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1