1.maui支持Android版本
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Android.App;
|
||||
using Android.Content.PM;
|
||||
using Android.OS;
|
||||
using AndroidX.Core.View;
|
||||
|
||||
namespace Hua.Todo.Maui;
|
||||
|
||||
@@ -18,8 +19,60 @@ public class MainActivity : MauiAppCompatActivity
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
|
||||
ConfigureSystemBars();
|
||||
|
||||
#if DEBUG
|
||||
Android.Webkit.WebView.SetWebContentsDebuggingEnabled(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activity 恢复时回调。
|
||||
/// 某些设备/启动链路会在恢复阶段重置系统栏样式,这里再次应用。
|
||||
/// </summary>
|
||||
protected override void OnResume()
|
||||
{
|
||||
base.OnResume();
|
||||
ConfigureSystemBars();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口焦点变化回调。
|
||||
/// 焦点切换后部分系统会重新应用主题色,需再次修正。
|
||||
/// </summary>
|
||||
/// <param name="hasFocus">是否获得焦点。</param>
|
||||
public override void OnWindowFocusChanged(bool hasFocus)
|
||||
{
|
||||
base.OnWindowFocusChanged(hasFocus);
|
||||
if (hasFocus)
|
||||
{
|
||||
ConfigureSystemBars();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置 Android 系统栏样式,避免默认紫色状态栏与页面视觉割裂。
|
||||
/// </summary>
|
||||
private void ConfigureSystemBars()
|
||||
{
|
||||
if (Window is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用接近页面背景的浅色系统栏,弱化顶部挖孔区域的突兀感。
|
||||
var systemBarColor = global::Android.Graphics.Color.ParseColor("#F8FAFC");
|
||||
Window.SetStatusBarColor(systemBarColor);
|
||||
Window.SetNavigationBarColor(systemBarColor);
|
||||
|
||||
// 保持内容在系统栏下方,避免顶部控件贴到状态栏区域。
|
||||
WindowCompat.SetDecorFitsSystemWindows(Window, true);
|
||||
|
||||
var insetsController = WindowCompat.GetInsetsController(Window, Window.DecorView);
|
||||
if (insetsController is not null)
|
||||
{
|
||||
insetsController.AppearanceLightStatusBars = true;
|
||||
insetsController.AppearanceLightNavigationBars = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user