Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 12 additions & 55 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,61 +1,18 @@
#if ANDROID
using Android.Graphics.Drawables;
using Android.Views;
using AndroidX.Core.View;
#endif
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Platform;
using Window = Microsoft.Maui.Controls.Window;

namespace MauiApp1Net10
{
using Window = Microsoft.Maui.Controls.Window;

namespace MauiApp1Net10
{
public partial class App : Application
{
public App()
{
InitializeComponent();

}
protected override void OnStart()
{
base.OnStart();
SetTheme(Application.Current.RequestedTheme);
RequestedThemeChanged += ThemeChangedEvent;
}

private void SetTheme(AppTheme theme)
{
#if ANDROID
var darkThemeStatusAndNavbarColor = Microsoft.Maui.Graphics.Color.FromArgb("#72e09a");
var lightThemeStatusAndNavbarColor = Microsoft.Maui.Graphics.Color.FromArgb("#BCCCDC");
var activity = Platform.CurrentActivity;
var window = activity?.Window;
if (window == null)
return;
//window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
//window.ClearFlags(WindowManagerFlags.TranslucentStatus);

var ac = theme == AppTheme.Dark ? darkThemeStatusAndNavbarColor.ToPlatform() : lightThemeStatusAndNavbarColor.ToPlatform();
window?.SetBackgroundDrawable(new ColorDrawable(ac));
//window?.SetStatusBarColor(ac);
//window?.SetNavigationBarColor(ac);
var wicc = WindowCompat.GetInsetsController(window, window?.DecorView);
if (wicc != null)
{
wicc.AppearanceLightStatusBars = theme == AppTheme.Dark ? false : true;
wicc.AppearanceLightNavigationBars = wicc.AppearanceLightStatusBars;
}
#endif
}

private void ThemeChangedEvent(object? sender, AppThemeChangedEventArgs e)
{
SetTheme(e.RequestedTheme);
}

protected override Window CreateWindow(IActivationState? activationState)
{
{
InitializeComponent();

}

protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new Tabbed());
}
}
}
}
18 changes: 11 additions & 7 deletions MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
Text="Open Modal"
Clicked="btnOpenModal_Clicked"
HorizontalOptions="Fill" />
<Button x:Name="btnToggleTheme"
Text="Toogle AppTheme"
Clicked="btnToggleTheme_Clicked"
HorizontalOptions="Fill" />
<Label x:Name="lblThemeInfo"
Text="Current Theme: "
SemanticProperties.HeadingLevel="Level3" />
<Button x:Name="btnToggleTheme"
Text="Toogle AppTheme"
Clicked="btnToggleTheme_Clicked"
HorizontalOptions="Fill" />
<Button x:Name="btnApplyAndroidOverride"
Text="Apply Android Theme Override"
Clicked="btnApplyAndroidOverride_Clicked"
HorizontalOptions="Fill" />
<Label x:Name="lblThemeInfo"
Text="Current Theme: "
SemanticProperties.HeadingLevel="Level3" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
50 changes: 43 additions & 7 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
namespace MauiApp1Net10
{
public partial class MainPage : ContentPage
#if ANDROID
using Android.Graphics.Drawables;
using AndroidX.Core.View;
using Microsoft.Maui.Platform;
#endif

namespace MauiApp1Net10
{
public partial class MainPage : ContentPage
{
int count = 0;

Expand Down Expand Up @@ -38,7 +44,37 @@ private void btnToggleTheme_Clicked(object sender, EventArgs e)
// break;
// }
}

}
}
}

}

private void btnApplyAndroidOverride_Clicked(object sender, EventArgs e)
{
ApplyReporterAndroidOverride(Application.Current.RequestedTheme);
}

private void ApplyReporterAndroidOverride(AppTheme theme)
{
#if ANDROID
var darkThemeStatusAndNavbarColor = Color.FromArgb("#72e09a");
var lightThemeStatusAndNavbarColor = Color.FromArgb("#BCCCDC");
var activity = Platform.CurrentActivity;
var window = activity?.Window;
if (window == null)
return;

var androidColor = theme == AppTheme.Dark
? darkThemeStatusAndNavbarColor.ToPlatform()
: lightThemeStatusAndNavbarColor.ToPlatform();

window.SetBackgroundDrawable(new ColorDrawable(androidColor));

var windowInsetsController = WindowCompat.GetInsetsController(window, window.DecorView);
if (windowInsetsController != null)
{
windowInsetsController.AppearanceLightStatusBars = theme != AppTheme.Dark;
windowInsetsController.AppearanceLightNavigationBars = windowInsetsController.AppearanceLightStatusBars;
}
#endif
}
}
}
160 changes: 76 additions & 84 deletions MauiApp1Net10.csproj
Original file line number Diff line number Diff line change
@@ -1,84 +1,76 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net10.0-android;net10.0-ios</TargetFrameworks>

<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<OutputType>Exe</OutputType>
<RootNamespace>MauiApp1Net10</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- Display name -->
<ApplicationTitle>Net10Statusbar</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.MauiApp1Net10</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">27.0</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<None Remove="Platforms\Android\Resources\values\styles.xml" />
</ItemGroup>

<ItemGroup>
<AndroidResource Include="Platforms\Android\Resources\values\styles.xml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="10.0.60" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.7" />
</ItemGroup>

<ItemGroup>
<MauiXaml Update="ModalPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Tabbed.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

<ItemGroup>
<None Update="ModalPage.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net10.0-android;net10.0-ios</TargetFrameworks>

<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<OutputType>Exe</OutputType>
<RootNamespace>MauiApp1Net10</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- Display name -->
<ApplicationTitle>Net10Statusbar</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.MauiApp1Net10</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">27.0</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="10.0.90-ci.pr35463.26319.50" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.7" />
</ItemGroup>

<ItemGroup>
<MauiXaml Update="ModalPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Tabbed.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

<ItemGroup>
<None Update="ModalPage.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
</ItemGroup>

</Project>
22 changes: 10 additions & 12 deletions Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
using Android.App;
using Android.Content.PM;
using Android.OS;
using Resource = Microsoft.Maui.Resource;

namespace MauiApp1
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace MauiApp1
{
[Activity(Theme = "@style/My.Theme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop,
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop,
ConfigurationChanges = ConfigChanges.SmallestScreenSize | ConfigChanges.ScreenLayout | ConfigChanges.ScreenSize
| ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.Locale | ConfigChanges.LayoutDirection | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle? savedInstanceState)
{
//Theme.ApplyStyle(Resource.Style.OptOutEdgeToEdgeEnforcement, force: false);
base.OnCreate(savedInstanceState);
}
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
}
}
9 changes: 0 additions & 9 deletions Platforms/Android/Resources/values-night/colors.xml

This file was deleted.

16 changes: 0 additions & 16 deletions Platforms/Android/Resources/values-night/styles.xml

This file was deleted.

10 changes: 0 additions & 10 deletions Platforms/Android/Resources/values/colors.xml

This file was deleted.

Loading