如何在一个片段中获得透明状态栏,在另一个片段中获得colorPrimaryDark?

时间:2018-08-02 19:38:50

标签: android material-design android-toolbar android-coordinatorlayout android-statusbar

我知道与此相关的问题很多,但阅读其中大​​部分内容只会使我感到困惑。给出的解决方案有时对每个人都是相反的,似乎对我以外的所有人都有效。请在下面查看我的xml。

activity_main

    <android.support.constraint.ConstraintLayout `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/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
   >

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:itemIconTint="@drawable/bottom_nav_colours"
        app:itemTextColor="@drawable/bottom_nav_colours"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation">
    </android.support.design.widget.BottomNavigationView>


<FrameLayout
    android:id="@+id/store_frame"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:fitsSystemWindows="true"
    app:layout_constraintBottom_toTopOf="@+id/navigation"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

</FrameLayout>

fragment_1,我需要透明状态栏

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
>

<android.support.design.widget.AppBarLayout
    android:id="@+id/tab_appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/price_list_toolbar"
        android:layout_width="match_parent"
        app:title="Price List"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:fitsSystemWindows="true"
       >
    </android.support.v7.widget.Toolbar>



    <android.support.design.widget.TabLayout
        android:id="@+id/liquor_type_tablayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:tabMode="scrollable">

       <!-- tab items-->
    </android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/price_list_viewpager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

片段_2

<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/tab_appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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


        <ImageView
            android:id="@+id/tab_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/liq_stores_queue"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />


        <android.support.v7.widget.Toolbar
            android:id="@+id/tab_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="top"
            android:layout_marginBottom="48dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/store_type"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:tabSelectedTextColor="@android:color/white">

<!--tab items-->

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

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

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

<android.support.v4.view.ViewPager
    android:id="@+id/store_viewpager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

最后是styles.xml

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:textColor">#212121</item>
    <item name="android:textColorPrimary">@color/textColourSecondary</item>
    <item name="android:textColorSecondary">@color/textColourSecondary</item>
    <item name="android:windowBackground">@color/windowBackground</item>

    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>
<!--
    <item name="android:statusBarColor">@android:color/transparent</item>
-->
<!--
    <item name="android:windowTranslucentNavigation">true</item>
-->
    <item name="android:listDivider">@drawable/my_custom_divider</item>
</style>

我肯定已经尝试了几乎所有解决方案,并且在这里一定做错了什么。如前所述,我的目标是使第一个片段中的图像完全透明,并使片段2中的colorPrimaryDark完全透明。

任何帮助将不胜感激。谢谢

0 个答案:

没有答案