添加高程/阴影工具栏上的pre-棒棒糖设备 [英] Add elevation/shadow on toolbar for pre-lollipop devices

查看:154
本文介绍了添加高程/阴影工具栏上的pre-棒棒糖设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新了我的Andr​​oid应用到新材料的设计,但我也想了一些阴影或标高添加到工具栏。似乎有通过图像/ 9-补丁做一些(哈克)的方式,但我不知道它可以通过支持库来完成。 (就像 CardView 可以拥有高度)

根据这个的另外一个问题回答,这是有可能通过包装工具栏 AppBarLayout ,但是这并没有为我工作。

我的布局:

 < XML版本=1.0编码=UTF-8&GT?;
< android.support.design.widget.AppBarLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
  机器人:layout_width =match_parent
  机器人:layout_height =WRAP_CONTENT>
    < android.support.v7.widget.Toolbar
            机器人:ID =@ + ID /工具栏
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:=了minHeight?ATTR / actionBarSize
            机器人:ATTR / colorPrimary后台=
            机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar
            应用程序:popupTheme =@风格/ ThemeOverlay.AppCompat.Light/>
< /android.support.design.widget.AppBarLayout>
 

我也尝试通过XML,并通过code设置高度,但是,这并不管用。

任何帮助将是AP preciated!先谢谢了。

更新:

因为我有我的工具栏布局,我的其他的布局,下面是我的主要布局之一:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>
    <包括
        布局=@布局/工具栏/>
    <片段
        类=OverAllField.XamarinAndroid.Fragments.Planning.PlanningFragment
        机器人:ID =@ + ID / PlanningFragment
        机器人:layout_width =match_parent
        机器人:layout_height =0dp
        机器人:layout_weight =1/>
< / LinearLayout中>
 

解决方案

为Android 5.0及以上版本:AppBarLayout自动提供/给出的影子布局。 您还可以通过增加AppBarLayout的高度安卓海拔=4DP

有关pre-棒棒糖:您可以使用下面的链接: http://blog.grafixartist.com/add -a - 工具栏 - 海拔-ON-pre-棒棒糖/

注意:工具栏也支持提升到它,使用安卓海拔=4DP

I updated my android app to the new material design, but I also wanted to add some shadow or elevation to the Toolbar. There seem to be some (hacky) ways of doing it via images/9-patches, but I wonder if it can be done via the support libraries. (just like the CardView can have elevation)

According to this answer on another question, this is possible by wrapping the Toolbar in a AppBarLayout, but this doesn't work for me.

My layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar
            android:id="@+id/Toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>

I also tried setting elevation via XML and through code, but that doesn't work either.

Any help would be appreciated! Thanks in advance.

Update:

Since I include my Toolbar layout in my other layouts, below is one of my main layouts:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <include
        layout="@layout/Toolbar" />
    <fragment
        class="OverAllField.XamarinAndroid.Fragments.Planning.PlanningFragment"
        android:id="@+id/PlanningFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

解决方案

For Android 5.0 and above : AppBarLayout automatically provides/gives shadow in the layout. You can also increase the elevation of the AppBarLayout by android:elevation="4dp"

For Pre-Lollipop : You can use the following link: http://blog.grafixartist.com/add-a-toolbar-elevation-on-pre-lollipop/

Note: Toolbar also supports elevation to it, using android:elevation="4dp"

这篇关于添加高程/阴影工具栏上的pre-棒棒糖设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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