Reputation: 75
I am working on a Xamarin.Forms app, where I was using a FormsApplicationActivity as my main activity and was able to customize the ActionBar with a custom view inside it (I put a Spinner in it, for some page)
But since there was a few UI / look and feel issues I upgraded to FormsAppCompatActivity. Since I did that I just CAN'T get my spinner in the toolbar / actionbar! No matter what I try!
This was basically the previous code, wroking with FormsApplicationActivity
var activity = (Activity)this.Context;
var bar = activityActionBar;
var dlp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
bar.CustomView = new Android.Widget.Button(activity) {
Text = "Click",
LayoutParameters = dlp,
};
bar.DisplayOptions = ActionBarDisplayOptions.ShowCustom;
What should I write to support FormsAppCompatActivity please?
Upvotes: 0
Views: 1439
Reputation: 185
When using FormsAppCompatActivity the NavigationRenderer on android creates a new toolbar internally. It is a private field so far I can see and cannot be accessed.
here is the code : https://github.com/xamarin/Xamarin.Forms/blob/d1a8477233b28e6a20c6f5d4a75128ec2a05e6dc/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs
See image for the specific code part. I am also trying now to get access to view. So just a note the action bar you are trying to edit is the wrong one. That one is created on activity startup.
UPDATE: maybe found a solution look here : https://forums.xamarin.com/discussion/69923/access-to-the-formsappcompatactivity-bar
Upvotes: 1