次の方法で共有


Android NavigationBar

NavigationBar を使用すると、Android プラットフォームのナビゲーション バーの外観をカスタマイズできます。

この機能を使用すると、次の設定を行うことができます。

バーの色

Color プロパティを使用すると、ナビゲーション バーの背景色の設定に使用する任意の Color を指定できます。

バー スタイル

Style プロパティを使用すると、ナビゲーションの前景色をカスタマイズできます。許可されている値は次のとおりです。

  • Default - これが既定値であり、システム テーマの設定が使用されます。
  • LightContent - 前景にライト テーマの色が適用されます。
  • DarkContent - 背景にダーク テーマの色が適用されます。

構文

次の例では、NavigationBar を使用して背景色を DarkSlateBlue に、前景スタイルを LightContent に設定する方法を示します。

ナビゲーション バーのサンプル

XAML

XAML 名前空間を含める

Note

これは、機能のプラットフォーム固有の性質とその用途により、ツールキット標準の名前空間とは異なる名前空間です。

XAML でこの機能を使用するには、次の xmlns をページまたはビューに追加する必要があります。

xmlns:droid="clr-namespace:CommunityToolkit.Maui.PlatformConfiguration.AndroidSpecific;assembly=CommunityToolkit.Maui"

したがって、以下のコードは、

<ContentPage
    x:Class="CommunityToolkit.Maui.Sample.Pages.NavigationBarPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

</ContentPage>

次のように、xmlns を含むように変更されます。

<ContentPage
    x:Class="CommunityToolkit.Maui.Sample.Pages.NavigationBarPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:droid="clr-namespace:CommunityToolkit.Maui.PlatformConfiguration.AndroidSpecific;assembly=CommunityToolkit.Maui">

</ContentPage>

NavigationBar の使用

NavigationBar は、XAML では次のように使用できます。

<ContentPage 
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:droid="clr-namespace:CommunityToolkit.Maui.PlatformConfiguration.AndroidSpecific;assembly=CommunityToolkit.Maui"
    x:Class="CommunityToolkit.Maui.Sample.Pages.NavigationBarPage"
    droid:NavigationBar.Color="DarkSlateBlue"
    droid:NavigationBar.Style="LightContent">
    
</ContentPage>

C#

NavigationBar は、C# では次のように使用できます。

using CommunityToolkit.Maui.PlatformConfiguration.AndroidSpecific;

class NavigationBarPage : ContentPage
{
    public NavigationBarPage()
    {
	this.On<Android>().SetColor(Colors.Purple);
	this.On<Android>().SetStyle(NavigationBarStyle.DarkContent);
    }
}

この機能の動作状態の例は、.「NET MAUI Community Toolkit サンプル アプリケーション」でご覧になれます。

API

NavigationBar のソース コードは、.NET MAUI Community Toolkit の GitHub リポジトリにあります。