gpt4 book ai didi

c# - StatusBar 和 MasterDetailPage Xamarin.Forms Android 之间出现白条

转载 作者:搜寻专家 更新时间:2023-11-01 09:37:06 25 4
gpt4 key购买 nike

我正在尝试构建一个简单的地理定位应用程序,该应用程序应在登录后在 map 上指向用户的位置。这部分工作正常,但我希望看到从状态栏和 View 中删除的空白区域,但我不知道如何删除。

这里有两个指向错误屏幕的链接:

enter image description here

enter image description here

我已经尝试过此处提供的解决方案:https://forums.xamarin.com/discussion/86568/unwanted-blank-space-above-navigation-bar-navigation-page但效果不佳:XAML 解决方案没有做任何事情,最后一个解决方案(检查构建版本)也使蓝色条消失,这不是研究的效果。

这是我的一些代码,如果您需要更多,请告诉我:

我显示 map 的页面:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.View.Detail"
xmlns:i18n="clr-namespace:MyApp"
Title=""
BackgroundColor="{StaticResource MainBackgroundColor}"
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps">
<StackLayout>
<ActivityIndicator IsRunning="{Binding IsBusy, Mode=TwoWay}" IsVisible="{Binding IsBusy, Mode=TwoWay}" Color="Blue"/>
<maps:Map VerticalOptions ="FillAndExpand" HorizontalOptions ="FillAndExpand"
x:Name="MyMap"
IsShowingUser="true"
MapType="Street"
/>
</StackLayout>
</ContentPage>

这是 MasterViewDetail

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.View.HomePage">

</MasterDetailPage>

感谢您的帮助!

编辑:

这是我的项目结构:

App(NavigationPage)
MainPage (ContentPage)
LoginPage (ContentPage)
HomePage (MasterDetailPage)
HomeDetail(ContentPage)
RegisterPage (ContentPage)

问题是我不是完全自由,我是实习生,必须听从客户的命令...

最佳答案

它是在 Xamarin 表单中构建的 - 它总是添加顶部填充。已经为此提出了一个错误,但不知道何时会修复。

我已经设法使用自定义渲染器来解决这个问题,该渲染器会执行一些 hacky 反射:

[assembly: ExportRenderer(typeof(MasterDetailPage), typeof(NoSpaceMasterDetailPageRenderer))]

namespace Droid.Renderers
{
public class NoSpaceMasterDetailPageRenderer : MasterDetailPageRenderer
{
/// <summary>
/// When adding a view, tweak the top padding if necessary.
/// According to:
/// https://github.com/xamarin/Xamarin.Forms/blob/589adbd3ef145ec85f9fe64eda008251c1cdb745/Xamarin.Forms.Platform.Android/AppCompat/MasterDetailPageRenderer.cs
/// The TopPadding is always set for the detail. This works fine when the master detail is shown normally, but
/// if it is inside a navigation page (such as the inspection view) then you get extra unwanted padding.
/// The 'fix' is to set the top padding to 0 for the detail, only of course the types and fields are hidden from us...
/// </summary>
/// <param name="child">Child.</param>
public override void AddView(Android.Views.View child)
{
try
{
var isMasterField = child.GetType().GetField("_isMaster", BindingFlags.NonPublic | BindingFlags.Instance);
if (isMasterField == null) return;

var isMaster = isMasterField.GetValue(child);
if ((bool)isMaster) return;

var parentField = child.GetType().GetField("_parent", BindingFlags.NonPublic | BindingFlags.Instance);
if (parentField == null) return;

var parent = parentField.GetValue(child) as MasterDetailPage;
if (parent == null || !(parent.Parent is NavigationPage)) return;

var topPaddingProperty = child.GetType().GetProperty("TopPadding", BindingFlags.Public | BindingFlags.Instance);
if (topPaddingProperty != null)
topPaddingProperty.SetValue(child, 0);
}
finally
{
base.AddView(child);
}
}
}
}

关于c# - StatusBar 和 MasterDetailPage Xamarin.Forms Android 之间出现白条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42226747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com