无阴影默认情况下工具栏上的? [英] No shadow by default on Toolbar?

查看:152
本文介绍了无阴影默认情况下工具栏上的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新我的应用程序与支持库V21新的工具栏。我的问题是,该工具栏没有任何投下阴影,如果我不设置高度属性。那是正常的行为,或者说我做错了什么?

我的code是:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
   机器人:layout_width =FILL_PARENT
   机器人:layout_height =FILL_PARENT
   机器人:方向=垂直>

   < android.support.v7.widget.Toolbar
       的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
       机器人:ID =@ + ID / my_awesome_toolbar
       机器人:layout_width =match_parent
       机器人:layout_height =WRAP_CONTENT
       机器人:ATTR / colorPrimary后台=
       机器人:海拔=4DP
       机器人:=了minHeight?ATTR / actionBarSize
       应用程序:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar
       应用程序:popupTheme =@风格/ ThemeOverlay.AppCompat.Light/>

   <的FrameLayout
       机器人:ID =@ + ID / FrameLayout1
       机器人:layout_width =match_parent
       机器人:layout_height =match_parent>
       。
       。
       。
 

和我的活动 - onCreate方法:

 工具栏=(栏)findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(工具栏);
 

解决方案

我最终制定自己的阴影为工具栏,认为它可能为寻找有帮助:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =顶
    机器人:方向=垂直>

    < android.support.v7.widget.Toolbar的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:ID =@ + ID /工具栏
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:背景=@色/ color_alizarin
        机器人:titleTextAppearance =@色/白
        应用程序:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar/>

    <的FrameLayout
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent>

        <! -  ****将您的内容在这里****  - >

        <查看
            机器人:layout_width =match_parent
            机器人:layout_height =5DP
            机器人:背景=@可绘制/ toolbar_dropshadow/>
    < /的FrameLayout>
< / LinearLayout中>
 

@绘制/ toolbar_dropshadow:

 < XML版本=1.0编码=UTF-8&GT?;
<形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:形状=矩形>
<梯度
    机器人:startColor =@机器人:彩色/透明
    机器人:endColor =#88333333
    机器人:角=90/>
< /形状>
 

@色/ color_alizarin

 <颜色名称=color_alizarin>#e74c3c< /彩色>
 

I'm updating my app with the new Toolbar from the support library v21. My problem is that the toolbar does not cast any shadow if I don't set the "elevation" attribute. Is that the normal behavior or I'm doing something wrong?

My code is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical">

   <android.support.v7.widget.Toolbar
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:id="@+id/my_awesome_toolbar"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="?attr/colorPrimary"
       android:elevation="4dp"
       android:minHeight="?attr/actionBarSize"
       app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

   <FrameLayout
       android:id="@+id/FrameLayout1"
       android:layout_width="match_parent"
       android:layout_height="match_parent">
       .
       .
       .

And in my Activity - OnCreate method:

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);

解决方案

I ended up setting my own drop shadow for the toolbar, thought it might helpful for anyone looking for it:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/color_alizarin"
        android:titleTextAppearance="@color/White"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- **** Place Your Content Here **** -->

        <View
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="@drawable/toolbar_dropshadow" />
    </FrameLayout>
</LinearLayout>

@drawable/toolbar_dropshadow:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
    android:startColor="@android:color/transparent"
    android:endColor="#88333333"
    android:angle="90"/>
</shape>

@color/color_alizarin

<color name="color_alizarin">#e74c3c</color>

这篇关于无阴影默认情况下工具栏上的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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