【问题标题】:Gradient color to the Android status bar - Ionic 3Android状态栏的渐变颜色 - Ionic 3
【发布时间】:2017-06-24 19:45:14
【问题描述】:

我有这样的渐变值:linear-gradient(to right, #0072FF,#00C6FF)。你能告诉我如何将它应用到Android status bar吗?

我已经尝试如下所示。但它不起作用。

this.statusBar.backgroundColorByHexString('linear-gradient(to right, #0072FF,#00C6FF)');

这种简单的工作正常:

 this.statusBar.backgroundColorByHexString('#0072FF');

【问题讨论】:

    标签: android cordova ionic2 ionic3 ionic-native


    【解决方案1】:

    您可以使用半透明状态栏并将渐变背景设置为与状态栏高度相同的布局。

    为设置状态栏半透明添加这一行到你的主题:

    <item name="android:windowTranslucentStatus">true</item>
    

    【讨论】:

    • 希望这适用于原生 Android 不?我正在使用混合离子。
    【解决方案2】:

    您可以像这样设置背景颜色渐变:

     Window window = activity.getWindow();
     Drawable background = activity.getResources().getDrawable(R.drawable.gradient_theme);
     window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
     window.setStatusBarColor(activity.getResources().getColor(R.color.transparent));
     window.setNavigationBarColor(activity.getResources().getColor(R.color.transparent));
     window.setBackgroundDrawable(background);
    

    但它适用于 api 21 及更高版本

    你的渐变主题在drawables中应该是这样的:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape>
                <gradient
                    android:angle="90"
                    android:startColor="@color/colorPrimary"
                    android:endColor="@color/color_primary_100"
                    android:type="linear" />
            </shape>
        </item>
    </selector>
    

    【讨论】:

    • 希望这适用于原生 Android 不?我正在使用混合离子。
    • 老实说,我在一个月前使用过它,但在 Android 本机代码中,希望这对你有用。如果不起作用告诉我们,我们可以找到另一种方法来做到这一点;)
    • 它不适用于 Ionic。我们必须使用这个 Cordova 插件。github.com/apache/cordova-plugin-statusbar
    猜你喜欢
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 2017-11-28
    • 1970-01-01
    • 2015-11-20
    相关资源
    最近更新 更多