android上带有分隔线的TabbedPage [英] TabbedPage with separator line on android
本文介绍了android上带有分隔线的TabbedPage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 TabbedPage 和子页面之间创建分隔符?iOS 默认有一个,但 android 没有.
iOS:
it is possible to create a separator between a TabbedPage and the child pages? iOS has one by default, but not android.
iOS:
安卓:
推荐答案
以下内容对我有用.BottomNavigationView.Height
在 OnElementChanged 中为 0,因此我们需要覆盖 OnLayout:
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 是行高.
这篇关于android上带有分隔线的TabbedPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文