ItGo.me Focus on IT Recommend

Home > android - How to change the TableSection text color with a custom renderer - Xamarin.Forms C#

android - How to change the TableSection text color with a custom renderer - Xamarin.Forms C#

I have a TableView with 3 TableSections in the root:

var tableView = new TableView
{
  RowHeight = 60,
  Root = new TableRoot
  {
    firstTableSection,
    secondTableSection,
    thirdTableSection,

  }
}

var firstTableSection = new TableSection("First")
{
  // Cells
}

var firstTableSection = new TableSection("First")
{
  // Cells
}

var firstTableSection = new TableSection("First")
{
  // Cells
}

How can you change the text color of the TableSection text with a custom renderer?

public class TestTableViewRenderer : Xamarin.Forms.Platform.Android.TableViewRenderer
{
    protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Xamarin.Forms.TableView> e)
    {
        base.OnElementChanged(e);

        // Not sure how to add this property here

    }
}
c# android xamarin xamarin.forms custom-renderer
|
  this question
asked Mar 7 '16 at 22:21 cfly24 704 6 17

 | 

2 Answers
2

I wound up using this solution:

https://forums.xamarin.com/discussion/32379/changing-the-title-color-of-a-tablesection

Which relies on two custom renderers:

Recommend:c# - Xamarin Form Custom Renderer for TableSection (iOS)

o that with Custom renderer in iOS c# ios xamarin xamarin.forms
  |
  this question edited Nov 17 '15 at 15:33 casillas 5,191 2 34 63 asked Nov 17 '15 at 15:19 gjfonte 62 1 9



| Know someone who

[assembly: ExportRenderer(typeof(TableView), typeof(CustomTableView))]
namespace APP.Droid
{
    public class CustomTableView : TableViewRenderer
    {
        protected override TableViewModelRenderer GetModelRenderer(global::Android.Widget.ListView listView, TableView view)
        {
            return new CustomTableViewModelRenderer(this.Context, listView, view);
        }

    }
}

and

[assembly: ExportRenderer(typeof(TableViewModelRenderer), typeof(CustomTableViewModelRenderer))]
namespace APP.Droid
{
    public class CustomTableViewModelRenderer : TableViewModelRenderer
    {
        public CustomTableViewModelRenderer(Context Context, global::Android.Widget.ListView ListView, TableView View)
            : base(Context, ListView, View)
        { }
        public override global::Android.Views.View GetView(int position, global::Android.Views.View convertView, ViewGroup parent)
        {
            var view = base.GetView(position, convertView, parent);

            var element = this.GetCellForPosition(position);

            if (element.GetType() == typeof(TextCell))
            {
                try
                {
                    var text = ((((view as LinearLayout).GetChildAt(0) as LinearLayout).GetChildAt(1) as LinearLayout).GetChildAt(0) as TextView);
                    var divider = (view as LinearLayout).GetChildAt(1);

                    text.SetTextColor(Android.Graphics.Color.Rgb(50, 50, 50));
                    divider.SetBackgroundColor(Android.Graphics.Color.Rgb(150, 150, 150));
                }
                catch (Exception) { }
            }

            return view;
        }
    }
}

|
  this answer
answered Sep 8 '16 at 22:00 Dan Beaulieu 9,147 9 58 87

 | 

might want to check out this thread on XF forum http://forums.xamarin.com/discussion/comment/189201/#Comment_189201


|
  this answer
answered Apr 5 '16 at 5:39 Mark J Radacz 1 1

 | 

Recommend:Xamarin forms custom renderer android stackoverflowerror

base.OnElementChanged(e); activity = this.Context as Activity; view =activity.LayoutInflater.Inflate(Resource.Layout.TestLayout, this, true); AddView(view); } however.. When i add the vi

oriUlr:http://stackoverflow.com/questions/35855286/how-to-change-the-tablesection-text-color-with-a-custom-renderer-xamarin-forms

------splitte line----------------------------