Android toolbar阴影悬浮高亮效果

Android toolbar阴影悬浮高亮效果

在android api 21一下toolbar是没有阴影效果的,后面找到解决api21以下实现阴影效果代码如下:

acticity.xml文件:

<android.support.design.widget.AppBarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    style="@style/ToolBarStyle"
    android:layout_height="wrap_content"
    android:background="@color/apptheme_main_dark"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    android:minHeight="@dimen/abc_action_bar_default_height_material">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/tv_title"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingRight="25dp"
                android:gravity="center|center_horizontal"
                android:textColor="@color/white"
                android:textSize="@dimen/abc_text_size_title_material"
                android:text="首页"/>
         </LinearLayout>
    </android.support.v7.widget.Toolbar>
    <View
        android:id="@+id/toolbar_shadow"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@drawable/toolbar_dropshadow" />
</android.support.design.widget.AppBarLayout>

注意上面的代码

<View
        android:id="@+id/toolbar_shadow"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@drawable/toolbar_dropshadow" />

这个是关键,

toolbar_dropshadow.xml

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

上面的shape就是一个阴影悬浮的效果啦:
看下面效果图:
这里写图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值