原色(有时)变为透明 [英] Primary color (sometimes) goes transparent

查看:335
本文介绍了原色(有时)变为透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用最新版本的SDK(API 21),并支持库21.0.2开发,并试图实施新材料设计的指导方针时,我一直有麻烦了。

材料设计说,我需要我的原色我的强调色,并将其应用在我的应用程序。但有时,当我打开应用程序的原色成为一些小部件透明的,它会恢复正常,直到我关闭应用程序(与后退按钮),然后重新启动它。

下面是原色是在我的工具栏透明的例子。

我使用蒂尔500作为我的主色,正如你所看到的,它是透明只在 android.support.v7.widget.Toolbar 。这也发生在我的抽屉式导航和(有时,有时没有)在另一个随机部件。

这是我的工具栏

 < android.support.v7.widget.Toolbar
        机器人:ID =@ + ID /工具栏
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:背景=@彩色/初级
        安卓了minHeight =?ATTR / actionBarSize
        应用:主题=@风格/ ThemeOverlay.AppCompat.ActionBar>

我试着 @色/初级?ATTR / colorPrimary ,但没有成功。

下面是我的主题(我不知道这是否是相关的,但以防万一):

 <样式名称=AppBaseTheme父=Theme.AppCompat.Light.NoActionBar>
    <项目名称=colorPrimary> @彩色/初级与LT; /项目>
    <项目名称=colorPrimaryDark> @彩色/ primary_dark< /项目>
    <项目名称=colorAccent> @颜色/重音< /项目>
    <项目名称=colorAccent> @颜色/重音< /项目>
    <项目名称=机器人:textColorPrimary>#FFF< /项目>    <项目名称=windowActionModeOverlay>真< /项目>
    <项目名称=机器人:textViewStyle> @风格/ Widget.TextView.White< /项目>
< /风格>

这正好与原色强调色工作正常反应。我的设备运行的是4.2.2,我没有在更多的设备进行检查。

工具栏与

活动

 < android.support.v4.widget.DrawerLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:ID =@ + ID / drawer_layout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:fitsSystemWindows =真正的>    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:方向=垂直>        < android.support.v7.widget.Toolbar
            机器人:ID =@ + ID / my_awesome_toolbar
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:ATTR / colorPrimary背景=
            安卓了minHeight =?ATTR / actionBarSize
            应用:主题=@风格/ ThemeOverlay.AppCompat.ActionBar/>        <的FrameLayout
            机器人:ID =@ + ID /容器
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            工具:忽略=MergeRootFrame/>
    < / LinearLayout中>    <! - 导航抽屉 - >    <的LinearLayout
        机器人:ID =@ + ID / navdrawer
        机器人:layout_width =240dp
        机器人:layout_height =match_parent
        机器人:layout_gravity =开始
        机器人:fitsSystemWindows =真
        机器人:方向=垂直>        <! - 在这也恰好 - >
        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:paddingLeft =16DP
            机器人:paddingRight =16DP
            机器人:paddingBottom会=16DP
            机器人:方向=垂直
            机器人:背景=@色/主>            <! - 一些东西 - >        < / LinearLayout中>        < ListView控件
            机器人:ID =@ + ID / left_drawer
            机器人:layout_height =match_parent
            机器人:layout_width =match_parent
            机器人:背景=@彩色/ black_light
            机器人:分=@彩色/灰度
            机器人:choiceMode =singleChoice/>
    < / LinearLayout中>< /android.support.v4.widget.DrawerLayout>


解决方案

问题是使用工具栏的背景的处理方式有关。这是工具栏的所有实例之间共享,因此,如果您倾向于改变工具栏的背景Alpha,您更改其他屏幕重用太绘制的阿尔法。

请确保您不使用工具栏的背景属性操纵,而不是新的背景颜色/绘制每个要对其进行自定义设置时间

I am developing with the latest SDK version (API 21) and Support Library 21.0.2 and I've been having trouble when trying to implement the new Material Design guidelines.

Material Design says that I need to have my primary color and my accent color and apply them over my app. But sometimes when I open the app the primary color becomes transparent in some widgets, it goes back to normal until I close the app (with the Back Button) and launch it again.

Here is an example of the primary color being transparent in my toolbar.

I am using Teal 500 as my primary color and, as you can see, it is transparent only in the android.support.v7.widget.Toolbar. This also happens on my Navigation Drawer and (sometimes , sometimes not) in another random widgets.

This is my Toolbar

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/primary"
        android:minHeight="?attr/actionBarSize"
        app:theme="@style/ThemeOverlay.AppCompat.ActionBar" >

I've tried with @color/primary and ?attr/colorPrimary with no success.

Here is my Theme (I don't know if it is related, but just in case):

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>     
    <item name="colorAccent">@color/accent</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:textColorPrimary">#fff</item>

    <item name="windowActionModeOverlay">true</item>
    <item name="android:textViewStyle">@style/Widget.TextView.White</item>
</style>

This just happens with the primary color, accent color works fine. My device is running 4.2.2 and I haven't checked on more devices.

Activity with Toolbar

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

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/my_awesome_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:ignore="MergeRootFrame" />
    </LinearLayout>

    <!-- The navigation drawer -->

    <LinearLayout
        android:id="@+id/navdrawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:orientation="vertical" >

        <!-- IN THIS IT ALSO HAPPENS -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:paddingBottom="16dp"
            android:orientation="vertical"
            android:background="@color/primary" >

            <!-- Some stuff -->

        </LinearLayout>

        <ListView
            android:id="@+id/left_drawer"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:background="@color/black_light"
            android:divider="@color/grey"
            android:choiceMode="singleChoice" />
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

解决方案

The problem is related with the way the toolbar's background is handled. It is shared between all instances of toolbar, so if you tend to change the toolbar's background alpha, you change the alpha of the drawable that is reused on other screens too.

Make sure you are not manipulating with the Toolbar's background properties, instead set the new background color/drawable each time you want to customize it.

这篇关于原色(有时)变为透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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