it is possible to create a separator between a TabbedPage and the child pages? iOS has one by default, but not android.
iOS:
Asked
Active
Viewed 729 times
0

Saftpresse99
- 849
- 7
- 16
2 Answers
1
You could implement it by using custom renderer
public class ExtendedTabbedPageRenderer : TabbedPageRenderer
{
Xamarin.Forms.TabbedPage tabbedPage;
BottomNavigationView bottomNavigationView;
private bool firstTime = true;
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.TabbedPage> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
tabbedPage = e.NewElement as ExtendedTabbedPage;
bottomNavigationView = (GetChildAt(0) as Android.Widget.RelativeLayout).GetChildAt(1) as BottomNavigationView;
bottomNavigationView.NavigationItemSelected += BottomNavigationView_NavigationItemSelected;
//add the line manualy here
}
}
void BottomNavigationView_NavigationItemSelected(object sender, BottomNavigationView.NavigationItemSelectedEventArgs e)
{
this.OnNavigationItemSelected(e.Item);
}
}

Lucas Zhang
- 18,630
- 3
- 12
- 22
-
Tried it: `if(e.NewElement != null) { bottomNavigationView = (GetChildAt(0) as Android.Widget.RelativeLayout).GetChildAt(1) as BottomNavigationView; GradientStrokeDrawable topBorderLine = new GradientStrokeDrawable { Alpha = 0x33 }; topBorderLine.SetStroke(1, Color.Red.ToAndroid()); LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { topBorderLine }); layerDrawable.SetLayerInset(0, 0, 0, 0, bottomNavigationView .Height - 2); _bottomNavigationView.SetBackground(layerDrawable); }` but no line. Only the background becomes grey. – Saftpresse99 Feb 25 '21 at 14:49
0
This following works for me. BottomNavigationView.Height
is 0 in OnElementChanged, so we need to override OnLayout:
public class CustomTabbedPageRenderer : TabbedPageRenderer {
private BottomNavigationView _bottomNavigationView;
public CustomTabbedPageRenderer(Context context) : base(context) {
}
protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e) {
base.OnElementChanged(e);
if(e.NewElement != null) {
_bottomNavigationView = (GetChildAt(0) as Android.Widget.RelativeLayout).GetChildAt(1) as BottomNavigationView;
}
}
protected override void OnLayout(bool changed, int l, int t, int r, int b) {
base.OnLayout(changed, l, t, r, b);
ShapeDrawable line = new ShapeDrawable() {
Alpha = 255
};
line.Paint.Color = Color.Red.ToAndroid();
line.Paint.SetStyle(Paint.Style.Fill);
var layerDrawable = new LayerDrawable(new Drawable[] { line });
layerDrawable.SetLayerInset(0, 0, 0, 0, _bottomNavigationView.Height - 5);
_bottomNavigationView.SetBackground(layerDrawable);
}
}
5 is the lineheight.

Saftpresse99
- 849
- 7
- 16