kitkat上的半透明StatusBar,工具栏上方为FrameLayout,并使用CoordinatorLayout [英] Translucent StatusBar on kitkat with FrameLayout above the Toolbar and using CoordinatorLayout

查看:131
本文介绍了kitkat上的半透明StatusBar,工具栏上方为FrameLayout,并使用CoordinatorLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过以下 FrameLayout在 kitkat 上实现 Translucent StatusBar code>,它可以地工作, CoordinatorLayout 就像这样:

I was trying to achieve Translucent StatusBar on kitkat with the following FrameLayout and it's working without CoordinatorLayout like this:

Layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="1">

    <FrameLayout
        android:id="@+id/statusbar"
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:background="@color/colorPrimaryDark" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:background="@color/colorPrimary" />

</LinearLayout>

这行在 Styles.xml-v19 当然是这样:

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

当然在 onCreate 中:

if (Build.VERSION.SDK_INT < 19) {

            FrameLayout statusbar = (FrameLayout) findViewById(R.id.statusbar);
            statusbar.setVisibility(View.GONE);
        }

而且有效:

但是,我想知道如何使用 CoordinatorLayout AppbarLayout

But, i'm wondering how we can achieve that with CoordinatorLayout and AppbarLayout?

以下是我的尝试:

<android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/toolbarCollapse"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <FrameLayout
                    android:id="@+id/statusbar"
                    android:layout_width="match_parent"
                    android:layout_height="25dp"
                    android:background="?attr/colorPrimaryDark" />

                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbarmain"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:background="@color/ColorPrimary"
                        app:layout_scrollFlags="scroll|enterAlways"
                        app:popupTheme="@style/ToolbarStylepopuptheme"
                        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />


            </android.support.design.widget.CollapsingToolbarLayout>

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:tabIndicatorColor="@android:color/white"
                app:tabIndicatorHeight="2dp"
                app:tabMode="scrollable" />

        </android.support.design.widget.AppBarLayout>

而且没有用。

更新:此操作也不起作用:

Update: Also this one is not working:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ui.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <FrameLayout
            android:id="@+id/statusBar"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:background="@color/colorPrimaryDark"
            android:translationZ="8dp" />

        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/root_coordinator"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/nestedscrollview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

...
...

任何解决方案

类似于 Google Play上的ADM应用设计。

另外,我们要说的是,我在<当我使用 CoordinatorLayout 时,a href = https://github.com/jgilfelt/SystemBarTint rel = nofollow noreferrer> SystemBarTint (条件相同) 。

Also, let's mention that, i've had the same problem with SystemBarTint when i was using CoordinatorLayout(same condition).

我不知道他们怎么做。

此外,还有一个很好的教程在这里, https://youtu.be/YCThIedqbCQ ,但这对我不起作用。

Also, there is a good tutorial here, https://youtu.be/YCThIedqbCQ but it doesn't work for me.

推荐答案

您可以不这样做吗?似乎不需要时将人造状态栏移到协调器布局中?

Can you not just do this? It seems like you're moving your faux status bar into the Coordinator layout when you don't need to?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">

<FrameLayout
    android:id="@+id/statusbar"
    android:layout_width="match_parent"
    android:layout_height="25dp"
    android:background="@color/colorPrimaryDark" />

<Coordinator>
    <AppBarLayout>
        <CollapsibleToolbarLayout>
            <Toolbar/>
        </CollapsibleToolbarLayout>
    </AppBarLayout>
    <NestedScrollView/>
</Coordinator>
</LinearLayout>

这篇关于kitkat上的半透明StatusBar,工具栏上方为FrameLayout,并使用CoordinatorLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆