###前提・実現したいこと
画面を横に固定し、ステータスバーとナビゲーションバーを隠してある画面を作成したいです。
画面上から下にスワイプするとステータスバーが表示され、右端から左にスワイプするとナビゲーションバーが表示される画面を作成したいと考えています。
いろいろと検索し、ナビゲーションバーを隠すために以下のコードを使っている方が多く見受けられたので記述しました。
NavigationPage.SetHasNavigationBar(this, false);
しかし、
CS0103 現在のコンテキストに 'NavigationPage' という名前は存在しません。
とエラーが出てしまい、クイックアクションとリファクタリングもどれを試してもうまくいきません。
これ以外に何か追加しないと動作しないといった情報が見当たらず、どうしたらよいものか詰まっています。
現在のコードは以下の通りです。
using Android.App; using Android.Widget; using Android.OS; using Android.Content.PM; namespace App8 { [Activity(Label = "App8", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); RequestedOrientation = ScreenOrientation.SensorLandscape; NavigationPage.SetHasNavigationBar(this, false); } } }
###追記
回答ありがとうございます。
Xamarin.Androidの方法ですと、
No resource found that matches the given name: attr 'windowNoTitle'. No resource found that matches the given name: attr 'windowActionBar'. Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Light'.
とエラーが表示されてしまい、コード内からクイックアクションやリファクタリングもできず、解決方法がわからなかったので断念しました。
Xamarin.Formsではないと使用できないとのことでしたので、Xamarin.Formsで作成しなおしました。
エラーは消えましたが、画面はNavigationPage.SetHasNavigationBar(this, false);を入れる前と変わらず、どこにコードを書いてよいかわからない状態です。またxamlファイルがないので、編集部分がわからない状態です。
現在以下の状態です。手探りですが、エラーが出ない場所にNavigationPage.SetHasNavigationBar(this, false);を入れました。
MainActivity.csにはどこに入れても「CS1503 引数 1: は 'XFApp3.Droid.MainActivity' から 'Xamarin.Forms.BindableObject' へ変換することはできません。」
と、エラーが出てしまったので編集していません。
App.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Xamarin.Forms; namespace XFApp3 { public class App : Application { public App() { NavigationPage.SetHasNavigationBar(this, false); // The root page of your application NavigationPage.SetHasNavigationBar(this, false); MainPage = new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { new Label { HorizontalTextAlignment = TextAlignment.Center, Text = "Welcome to Xamarin Forms!" } } } }; NavigationPage.SetHasNavigationBar(this, false); } protected override void OnStart() { NavigationPage.SetHasNavigationBar(this, false); // Handle when your app starts } protected override void OnSleep() { NavigationPage.SetHasNavigationBar(this, false); // Handle when your app sleeps } protected override void OnResume() { NavigationPage.SetHasNavigationBar(this, false); // Handle when your app resumes } } }