簡體   English   中英

使用Android支持設計庫在工具欄上苦苦掙扎

[英]Struggling with toolbar using android support design library

我想讓RecyclerView上的透明工具欄包含自定義的相對布局,我稱其為customHeader。 我在主要活動中的布局如下:

我使用android支持設計庫v.22.2.1和其他具有相同版本的支持庫都很好,除了,盡管我從工具欄布局中刪除了背景色,但我使用的是原色而不是透明的工具欄。

這是我得到的結果: 在此處輸入圖片說明

我想要的是透明的工具欄,但僅當我向上滾動時才應填充原色

我的activity_main布局是:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           >
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

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

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

        <FrameLayout
            android:id="@+id/content_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/btnCreate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_marginBottom="@dimen/btn_fab_margins"
            android:layout_marginRight="@dimen/btn_fab_margins"
            android:src="@drawable/share"
            app:borderWidth="0dp"
            app:elevation="6dp"
            app:pressedTranslationZ="12dp" />
    </android.support.design.widget.CoordinatorLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/vNavigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/WHITE"
        app:itemIconTint="@color/primary_text"
        app:itemTextColor="@color/primary_text"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/drawer_menu"/>
</android.support.v4.widget.DrawerLayout>

那么我片段中的布局是:

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

    <!-- Story list in main page -->
    <com.creativeLabs.news.util.MySwipeRefreshLayout
        android:id="@+id/swipe_refresh_story"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity$PlaceholderFragment">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/list_view_story_list"
            android:overScrollMode="never"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </com.creativeLabs.news.util.MySwipeRefreshLayout>
</RelativeLayout>

我的customHeader布局是:

<?xml version="1.0" encoding="utf-8"?>
<com.creativeLabs.news.ui.view.SlideTopStory
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_marginBottom="@dimen/story_list_item_margin_vertical"
    android:layout_width="match_parent"
    android:layout_height="@dimen/slide_image_height">

        <ImageView
            android:id="@+id/ivStoryimage"
            android:contentDescription="@string/story_title"
            android:scaleType="centerCrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            />

        <ProgressBar
            android:id="@+id/loading_bar"
            android:layout_centerInParent="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <!-- A mask view -->
        <View
            android:background="@drawable/title_slide_background"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="70dip"/>
        <View
            android:background="@drawable/title_slide_background1"
            android:layout_alignParentTop="true"
            android:layout_width="match_parent"
            android:layout_height="70dip"/>

        <TextView
            android:id="@+id/title"
            android:layout_alignParentBottom="true"
            android:textColor="@android:color/white"
            android:textSize="@dimen/text_size_large"
            android:gravity="center_vertical"
            android:paddingLeft="@dimen/slide_image_title_padding"
            android:paddingRight="@dimen/slide_image_title_padding"
            android:paddingEnd="@dimen/slide_image_title_padding"
            android:layout_marginBottom="@dimen/slide_image_title_margin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

</com.creativeLabs.news.ui.view.SlideTopStory>

我的應用程式thems.xml:

  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="colorControlNormal">@android:color/white</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    .......
    .......

in the manifest -> application tag:
android:theme="@style/AppTheme.WithoutActionBar">   

在我的活動和片段中,除了工具欄顏色或其他處理方式外,我沒有編碼任何東西

setSupportActionBar(toolbar);
    getSupportActionBar().setHomeButtonEnabled(true);
    toolbar.setNavigationIcon(getActionBarIconResource());

那么,為什么工具欄使應用成為原色? 我怎樣才能得到一個透明的工具欄..任何幫助請? 提前致謝

<android.support.v7.widget.Toolbar  
 app:popupTheme="@style/ThemeOverlay.AppCompat.Light"  
 app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />   

檢查如何應用您的樣式

您在哪里將其設置為透明(alpha?)

View.getBackground().setAlpha(..) ;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM