.Net-Avalonia学习笔记(十一)-安卓APP设置横屏与全屏

一、横屏

1、原本在Android中设置

  在 Android 中设置安卓应用为横屏模式,以下是一般的步骤:
    • 在安卓项目中,需要修改AndroidManifest.xml文件。这个文件位于安卓项目的Properties文件夹下。
    • 找到<activity>标签,在其中添加android:screenOrientation="landscape"属性。例如:
<activity android:name="com.companyname.yourapp.MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="landscape">
  • 这样就可以将整个 Activity(通常是应用的主界面)设置为横屏模式。
  • 如果你的应用有多个 Activity,并且希望全部都是横屏模式,那么需要在每个 Activity 的标签中都添加这个属性。

2、参考上例在Avalonia中设置

  在 MainActivity 中设置安卓应用为横屏模式,以下

    [Activity(
        Label = "AvaloniaTestApp.Android",
        Theme = "@style/MyTheme.NoActionBar",
        Icon = "@drawable/icon",
        MainLauncher = true,
        ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.UiMode,
        ScreenOrientation =ScreenOrientation.Landscape)]
    public class MainActivity : AvaloniaMainActivity<App>
    {
        protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
        {
            //RequestedOrientation=ScreenOrientation.Landscape;
            return base.CustomizeAppBuilder(builder)
                .WithInterFont();
        }
    }

二、全屏

using Avalonia.Controls;
using System;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;

namespace AvaloniaApp1.Views;

public partial class MainView : UserControl
{
    public MainView()
    {
        InitializeComponent();
    }

    private void Button_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
    {
        Console.WriteLine("12334432112");
        var insetsManager = TopLevel.GetTopLevel(this).InsetsManager;

        insetsManager.IsSystemBarVisible = false;
        insetsManager.DisplayEdgeToEdge = true;
    }

    private void UserControl_Loaded(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
    {
        Console.WriteLine("223333111");
        var insetsManager = TopLevel.GetTopLevel(this).InsetsManager;

        insetsManager.IsSystemBarVisible = false;
        insetsManager.DisplayEdgeToEdge = true;
    }
}

 

posted @ 2024-11-25 11:06  ꧁执笔小白꧂  阅读(95)  评论(1编辑  收藏  举报