问题描述
我一直在尝试在Xamarin Forms(具有透明状态栏的背景图像)中创建以下布局:
I've been trying to create the following layout in Xamarin Forms, a background image with a transparent status bar:
我想要一个带有透明状态栏的背景图像,如上面的图像.我的问题是:
I want to have a background image with a transparent status bar like the image above. My issues are:
-
我无法在Android上执行此操作,而在iOS上很好.我尝试将状态栏设置为透明,并且也以编程方式进行了设置,看来我的形象并没有落后于状态栏..我没有在互联网上找到任何有关它的相关信息,只是更改了我做过但没有用的AppTheme信息.
I am unable to do this on Android while on iOS it's good. I've tried to set my status bar transparent and did it programmatically as well, it seems that my image just don't get behind the status bar.. I didn't found any relevant information on internet about it, only to change the AppTheme information which i did but is not working.
在iOS上,状态栏文本颜色为黑色,因此也无法将其更改为白色.
On iOS, the status bar text color is black and as well am unable to change it to white.
我已经花了两个星期的时间来尝试找出方法,但是仍然无法执行.我应该为此创建一个自定义渲染器吗?还是有更简单的方法来做到这一点?
I've spend two weeks trying to found out how to do it but am still unable to do it.. Should i create a custom renderer for this? Or is there a much more simpler way to do it?
推荐答案
您可以使用此解决方案并应用颜色.
You can use this solution and apply color.
在new Android.Graphics.Color(18, 52, 86, 255)
中,您可以传递RGBA
作为颜色.
In new Android.Graphics.Color(18, 52, 86, 255)
you can pass RGBA
for color.
在MainActivity
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));
}
在MainActivity
App.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
这篇关于Xamarin形成带有透明状态栏的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!