我试图通过创建如下所示的基本页面来删除MasterDetailPage上的汉堡包图标:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BasePage : ContentPage
{
public IList<View> BasePageContent => BaseContentGrid.Children;
public BasePage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
//Fix top page margin requirement depending on the current device running the app
StatusRowDef.Height = DependencyService.Get<IDeviceInfo>().StatusBarHeight;
NavigationBarDef.Height = DependencyService.Get<IDeviceInfo>().NavigationBarHeight;
//Hide the Xamarin Forms built in navigation header
NavigationPage.SetHasNavigationBar(this, false);
}
}
然后这就是我获得导航高度的方式
public class DeviceInfo : IDeviceInfo
{
public float StatusBarHeight => 0;
public float NavigationBarHeight => GetNavigationBarSize();
internal static Func<Context> GetContext { get; set; }
private static float GetNavigationBarSize()
{
float heightInPx = 0;
var res = GetContext().Resources;
int resourceId = res.GetIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0)
{
heightInPx = res.GetDimensionPixelSize(resourceId);
}
return heightInPx;
}
}
现在的结果是我认为是Pixel(示例结果= 144)。
使用144px的结果会使我的自定义页面显示更大的导航栏,如下所示
我在这方面做错了什么?我需要将其转换为某种东西吗?