【问题标题】:change navigation bar color like canva app像canva app一样改变导航栏颜色
【发布时间】:2019-04-02 03:49:56
【问题描述】:

我想要设计像 canva 应用程序这样的启动画面。喜欢

(此截图取自 android API 版本 26)。

我在 Activity.java 中试过这段代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
    }
}

而XML代码是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/gradient_splash_screen">

    <FrameLayout
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_centerInParent="true"
        android:background="@drawable/icon_splash_screen">

        <TextView
            android:id="@+id/tv_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="@string/app_name"
            android:textColor="#678ee4"
            android:textSize="28sp" />
    </FrameLayout>
</RelativeLayout>

我最近提到了this question,但它不足以将导航栏图标颜色更改为白色。

【问题讨论】:

    标签: android


    【解决方案1】:

    我看到屏幕截图中没有操作栏。

    您可以创建一个没有操作栏、透明状态栏和透明导航栏的屏幕。

    创建如下样式。

        <style name="AppTheme.NoActionBar" parent="AppTheme">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>
    
        <style name="AppTheme.NoActionBar.TranslucentStatus" parent="AppTheme.NoActionBar">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    </style>
    

    将上述AppTheme.NoActionBar.TranslucentStatus 应用于manifest 中的活动

    上述方法仅适用于棒棒糖(v21)

    【讨论】:

    • 这是真的,但是请看Canva App的截图,里面有白色的导航图标!
    • 当我尝试这个代码导航图标颜色没有改变。
    猜你喜欢
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 2018-04-27
    相关资源
    最近更新 更多