作者:手机用户2502932551 | 来源:互联网 | 2023-05-17 11:34
Androidtoolbar阴影悬浮高亮效果在androidapi21一下toolbar是没有阴影效果的,后面找到解决api21以下实现阴影效果代码如下:acticity.xml
Android toolbar阴影悬浮高亮效果
在android api 21一下toolbar是没有阴影效果的,后面找到解决api21以下实现阴影效果代码如下:
acticity.xml文件:
.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_hljs-string">"match_parent"
android:layout_hljs-string">"wrap_content"
app:theme=
"@style/ThemeOverlay.AppCompat.Dark.ActionBar">
.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_hljs-string">"match_parent"
hljs-string">"@style/ToolBarStyle"
android:layout_hljs-string">"wrap_content"
android:background="@color/apptheme_main_dark"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:minhljs-string">"@dimen/abc_action_bar_default_height_material">
android:layout_hljs-string">"match_parent"
android:layout_hljs-string">"wrap_content">
android:id="@+id/tv_title"
android:layout_hljs-string">"match_parent"
android:layout_hljs-string">"match_parent"
android:paddingRight="25dp"
android:gravity="center|center_horizontal"
android:textColor="@color/white"
android:textSize="@dimen/abc_text_size_title_material"
android:text="首页"/>
.support
.v7
.widget.Toolbar>
android:id="@+id/toolbar_shadow"
android:layout_hljs-string">"match_parent"
android:layout_hljs-string">"1dp"
android:background="@drawable/toolbar_dropshadow" />
.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就是一个阴影悬浮的效果啦:
看下面效果图: