如何在Xamarin Forms中更改文本颜色状态栏?

时间:2019-01-22 00:03:21

标签: xamarin xamarin.forms xamarin.android

我想将状态栏设计为白色,但是文本和通知图标的颜色是相同的颜色,那么如何更改状态栏的文本颜色?

状态栏颜色

之前

enter image description here

之后enter image description here

3 个答案:

答案 0 :(得分:1)

Okey,@ Harry Android与iOS有所不同。

  

现在我的优先级是Android,是的。 iOS可能会在未来

Android:

Android 6.0启动,Google正式提供了支持,并在style属性中配置android:windowLightStatusBar 是的,当设置为true时,状态栏的背景颜色为浅色时,状态栏的文本颜色将为灰色。 true的{​​{1}}相同。如下:

false

在xamarin中,表单可以跟随this link获得成功。

基本上,您必须使用<style name="MainTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> <!--If you are using revision 22.1 please use just windowNoTitle. Without android:--> ... <item name="android:windowLightStatusBar">false</item> </style> 代替FormsAppCompatActivityFormsApplicationActivity代替Theme.AppCompat.Light.NoActionBar

如果要让某些页面显示不同的样式,可以更改活动的主题。

Theme.Material.Light

IOS:

(1),将跟随键值添加到Project.IOS中的<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".Activity.SecondActivity" android:launchMode="singleTop" android:theme="@style/customttheme"/> </application>

info.plist

(2)不使用代码:

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

(3),或使用代码设置状态栏的文本颜色,<key>UIStatusBarStyle</key> <string>UIStatusBarStyleLightContent</string> 中的方法FinishedLaunching设置如下:

AppDelegate.cs

(4)如果要在启动应用程序时更改页面的颜色,可以使用 app.StatusBarStyle = UIStatusBarStyle.LightContent; 方法通过custome ViewControllerRenderer for IOS:

ViewDidLoad()

答案 1 :(得分:0)

请参见以下答案:background status bar color

根据此链接,您需要将BarBackgroundColorBarTextColor的值设置为特定的颜色,如下所示:

...
MainPage = new MainPageUser();

  //Background color
  MainPage.SetValue(NavigationPage.BarBackgroundColorProperty, Color.Black);

  //Title color
  MainPage.SetValue(NavigationPage.BarTextColorProperty, Color.White);
...

也:

  

但是,就像您可能现在注意到的那样,iOS的状态栏位于顶部   也是黑色的,您需要在以下位置更改Info.plist文件   您的ios项目并使用以下命令打开它(右键单击并选择“打开方式”)   xml编辑器,并添加以下代码行:

根据此评论,您需要像这样更改info.plist:

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

希望这会有所帮助。

答案 2 :(得分:0)

在iOS 12及更高版本的Xamarin.Forms中,您只需在info.plist中创建此

  • 打开Info.Plist
  • 切换到“源”标签
  • 添加新条目
  • 键入“ UIStatusBarStyle”(不带引号)

您可以在右侧选择颜色。

Info.plist BarColor

相关问题