回答編集履歴
1
より簡潔に済むように修正
answer
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
コードでステータスバーのスタイルを変更すればいいので、[カスタムレンダラー](https://docs.microsoft.com/ja-jp/xamarin/xamarin-forms/app-fundamentals/custom-renderer/)を使います。
|
2
|
-
以下のように`
|
2
|
+
以下のように`NavigationPage`をカスタマイズします。
|
3
3
|
|
4
4
|
**.NET Standardプロジェクト**
|
5
|
-
```C#
|
6
|
-
namespace StatusBar
|
7
|
-
{
|
8
|
-
public class CustomContentPage : ContentPage
|
9
|
-
{
|
10
|
-
}
|
11
|
-
}
|
12
|
-
```
|
13
5
|
|
14
6
|
```C#
|
15
7
|
namespace StatusBar
|
@@ -28,12 +20,11 @@
|
|
28
20
|
```
|
29
21
|
|
30
22
|
**iOSプロジェクト**
|
31
|
-
|
32
23
|
```C#
|
33
|
-
[assembly: ExportRenderer(typeof(
|
24
|
+
[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustomNavigationRenderer))]
|
34
25
|
namespace StatusBar.iOS
|
35
26
|
{
|
36
|
-
public class
|
27
|
+
public class CustomNavigationRenderer : NavigationRenderer
|
37
28
|
{
|
38
29
|
public override UIStatusBarStyle PreferredStatusBarStyle()
|
39
30
|
{
|
@@ -43,20 +34,6 @@
|
|
43
34
|
}
|
44
35
|
```
|
45
36
|
|
46
|
-
```C#
|
47
|
-
[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustomNavigationRenderer))]
|
48
|
-
namespace StatusBar.iOS
|
49
|
-
{
|
50
|
-
public class CustomNavigationRenderer : NavigationRenderer
|
51
|
-
{
|
52
|
-
public override UIViewController ChildViewControllerForStatusBarStyle()
|
53
|
-
{
|
54
|
-
return VisibleViewController.ChildViewControllers.First();
|
55
|
-
}
|
56
|
-
}
|
57
|
-
}
|
58
|
-
```
|
59
|
-
|
60
37
|
以下のように使います。
|
61
38
|
```C#
|
62
39
|
MainPage = new CustomNavigationPage(new Webview())
|
@@ -64,13 +41,4 @@
|
|
64
41
|
BarBackgroundColor = Color.Crimson,
|
65
42
|
BarTextColor = Color.White,
|
66
43
|
};
|
67
|
-
```
|
68
|
-
|
69
|
-
```xml
|
70
|
-
<local:CustomContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
71
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
72
|
-
xmlns:local="clr-namespace:StatusBar"
|
73
|
-
x:Class="StatusBar.Webview">
|
74
|
-
<WebView Source="https://www.youtube.com" />
|
75
|
-
</local:CustomContentPage>
|
76
44
|
```
|