.Net MAUI 安卓状态栏透明、半透明、全屏

测试机器为:美帝良心想 padpro11,系统版本:安卓11

开发环境:Microsoft Visual Studio Community 2022 (64 位) - Current 版本 17.3.6

MAUI版本:6.0.541

Demo 源码

方法:

一、在Platforms→Resources→values文件夹下创建一个style.xml文件,里面包含一个资源主题名字叫 MainTheme,名字自己取, "继承"于MAUI默认的启动主题即parent = Maui.SplashTheme,然后写入三个状态栏、导航栏配置,如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="MainTheme" parent="Maui.SplashTheme">
		<item name="android:windowTranslucentStatus">false</item>
		<item name="android:windowTranslucentNavigation">true</item>
		<item name="android:statusBarColor">@android:color/transparent</item>
	</style>
</resources>

 VS中的位置:

截图:

二、打开Platforms→MainActivity.cs文件,

1.更改特性

//原 [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
//改为下面Theme = "@style/(你创建主题的名字)"
[Activity(Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]

2.重写OnCreate方法即可

        protected override void OnCreate(Bundle savedInstanceState)
        {
            //全屏,即隐藏状态栏,时间、信号这些也不可见
            // Window.SetFlags(Android.Views.WindowManagerFlags.Fullscreen, Android.Views.WindowManagerFlags.Fullscreen);

            //半透明 任务栏
            // Window.SetFlags(Android.Views.WindowManagerFlags.TranslucentStatus, Android.Views.WindowManagerFlags.TranslucentStatus);

            //全透明任务栏
            Window.SetFlags(Android.Views.WindowManagerFlags.TranslucentNavigation, Android.Views.WindowManagerFlags.TranslucentNavigation);


            //设置状态栏、导航栏色颜色为透明
            Window.SetStatusBarColor(Android.Graphics.Color.Transparent);
            Window.SetNavigationBarColor(Android.Graphics.Color.Transparent);

            base.OnCreate(savedInstanceState);
        }

截图:

VS中文件:

三、运行效果:

1.MAUI默认状态:

启动画面(有状态栏),程序运行状态(有状态栏)

2.状态栏全透明 

启动画面 (有状态栏,且透明) ,程序运行状态(有状态栏,且透明)

 

3.全屏无状态栏

 

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值