솔루션을 찾았습니다.
이렇게하려면 사용자 지정 렌더러를 만들어야합니다.
아래 찾을 Xamarin.Droid 프로젝트에서 PageRenderer에 대한 코드를 언급하십시오 :
[assembly: ExportRenderer(typeof(ContentPage), typeof(MyContentPageRenderer))]
네임 스페이스 ProjectName.Droid.Renderer
{
public class MyContentPageRenderer : PageRenderer
{
public MyContentPageRenderer()
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
}
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
float pixWidth = (float)Resources.DisplayMetrics.WidthPixels;
float fdpWidth = (float)App.Current.MainPage.Width;
float pixPerDp = pixWidth/fdpWidth;
this.Element.Padding = new Thickness(0, MainActivity.StatusBarHeight/pixPerDp, 0, 0);
} } }
그리고 "MainActivity"의 코드를 찾아주세요 StatusBarHeight 계산에 대해 아래에 언급 된대로 :
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
public static int StatusBarHeight;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
Window.DecorView.SystemUiVisibility = 0;
var statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
statusBarHeightInfo.SetValue(this, 0);
Window.SetStatusBarColor(new Android.Graphics.Color(18, 52, 86, 255));
}
LoadApplication(new App());
StatusBarHeight = getStatusBarHeight();
}
public int getStatusBarHeight()
{
int statusBarHeight = 0, totalHeight = 0, contentHeight = 0;
int resourceId = Resources.GetIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0)
{
statusBarHeight = Resources.GetDimensionPixelSize(resourceId);
}
return statusBarHeight;
}
}
이것은 내 문제를 해결했습니다.