首页 > 解决方案 > 如何更改 Xamarin Forms 中的文本颜色状态栏?

问题描述

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

状态栏颜色

之前

在此处输入图像描述

之后在此处输入图像描述

标签: xamarinxamarin.formsxamarin.android

解决方案


好的,@Harry Android 与 IOS 不同。

现在我的首要任务是Android,所以是的。iOS 可能在未来

安卓:

Android 6.0 开始,Google 官方提供支持,android:windowLightStatusBar在 style 属性中配置 是,当设置为true时,当状态栏的背景颜色为浅色时,状态栏的文字颜色会变灰。同理truefalse如下:

<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>

在 xamarin.forms 中可以点击此链接获得成功。

基本上你必须使用FormsAppCompatActivity代替FormsApplicationActivityTheme.AppCompat.Light.NoActionBar代替Theme.Material.Light

如果希望某些页面显示不同的样式,可以在活动的主题中进行更改。

<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>

IOS:

info.plist(1)、在Project.IOS中添加follow key-value :

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

(2) 不使用代码:

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>

(3),或者使用代码设置状态栏的文字颜色,设置方法FinishedLaunching如下AppDelegate.cs

 app.StatusBarStyle = UIStatusBarStyle.LightContent;

(4)如果想在启动应用后某些页面改变颜色,可以为IOS自定义 ,方法:ViewControllerRendererViewDidLoad()

UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;

推荐阅读