安卓:Appcompat 21如何添加阴影动作条 [英] Android: Appcompat 21 how to add shadow on actionbar
问题描述
我添加的新appcompat新材料设计动作条我用的是新的工具栏小工具。我设置一个自定义背景的工具栏上的XML,但我的问题是,不显示在动作条的阴影。你知道如何做到这一点?
工具栏code
< android.support.v7.widget.Toolbar的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / my_awesome_toolbar
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =match_parent
机器人:=了minHeight?ATTR / actionBarSize
机器人:背景=@可绘制/ ab_background_textured
应用程序:主题=@风格/ MyTheme的
应用程序:popupTheme =@风格/ MyTheme.Popup/>
MyTheme的风格
<样式名称=MyTheme的父=Theme.AppCompat.Light.DarkActionBar>
<项目名称=机器人:textColorPrimary> @色/ abc_primary_text_material_dark< /项目>
<项目名称=actionMenuTextColor> @色/ abc_primary_text_material_dark< /项目>
<项目名称=机器人:textColorSecondary>#ffff8800< /项目>
< /风格>
MyTheme.Popup风格
<样式名称=MyTheme.Popup父=ThemeOverlay.AppCompat.Dark>
<项目名称=机器人:文字颜色>#FFFFFF< /项目>
< /风格>
更新
像@Justin鲍威尔建议我加入 actionBarStyle
我的主题,但仍然没有阴影。
MyTheme的风格(更新)
<样式名称=MyTheme的父=Theme.AppCompat.Light.DarkActionBar>
<项目名称=机器人:textColorPrimary> @色/ abc_primary_text_material_dark< /项目>
<项目名称=actionMenuTextColor> @色/ abc_primary_text_material_dark< /项目>
<项目名称=机器人:textColorSecondary>#ffff8800< /项目>
<项目名称=机器人:actionBarStyle> @风格/ Widget.AppCompat.Light.ActionBar.Solid.Inverse< /项目>
< /风格>
我发现,在谷歌IO应用的解决方案是可以接受我自己,但没有看到博客或者发帖#1完全解释它。你可以做的是从<一个抓住他们的Apache 2许可的抽屉影子资产href="https://github.com/google/iosched/blob/master/android/src/main/res/drawable-xxhdpi/bottom_shadow.9.png">https://github.com/google/iosched/blob/master/android/src/main/res/drawable-xxhdpi/bottom_shadow.9.png然后在你的活动布局:
&LT; RelativeLayout的机器人:layout_width =match_parent
机器人:layout_height =match_parent&GT;
&LT;包括机器人:ID =@ + ID /工具栏
布局=@布局/工具栏/&GT;
&LT;的FrameLayout机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_below =@ ID /工具栏
机器人:前景=@可绘制/ header_shadow&GT;
&LT; - !你的东西在这里 - &GT;
&LT; /的FrameLayout&GT;
&LT; / RelativeLayout的&GT;
而头阴影
&LT; XML版本=1.0编码=UTF-8&GT?;
&LT;资源&GT;
&LT;项目名称=header_shadowTYPE =绘制&GT; @可绘制/ bottom_shadow&LT; /项目&GT;
&LT; /资源&GT;
有关API的级别和LT; 21。就像<一href="https://github.com/google/iosched/blob/master/android/src/main/res/values/refs.xml">https://github.com/google/iosched/blob/master/android/src/main/res/values/refs.xml和<一href="https://github.com/google/iosched/blob/master/android/src/main/res/values-v21/refs.xml">https://github.com/google/iosched/blob/master/android/src/main/res/values-v21/refs.xml.
和是精心制作的,这里是toolbar.xml
&LT; XML版本=1.0编码=UTF-8&GT?;
&LT; android.support.v7.widget.Toolbar
的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID /工具栏
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:ATTR / colorPrimary后台=
机器人:海拔=4DP
应用程序:主题=@风格/ ToolbarTheme
应用程序:popupTheme =@风格/ AppTheme/&GT;
I add the new material design actionbar from the new appcompat and I use the new toolbar widget. I set a custom background on the toolbar on xml but my problem is that the drop shadow from the actionbar is not displayed. Do you know how to do this?
Toolbar code
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@drawable/ab_background_textured"
app:theme="@style/MyTheme"
app:popupTheme="@style/MyTheme.Popup"/>
MyTheme style
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColorPrimary">@color/abc_primary_text_material_dark</item>
<item name="actionMenuTextColor">@color/abc_primary_text_material_dark</item>
<item name="android:textColorSecondary">#ffff8800</item>
</style>
MyTheme.Popup style
<style name="MyTheme.Popup" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:textColor">#ffffff</item>
</style>
Update
Like @Justin Powell suggested I add the actionBarStyle
on my theme but still there is no drop shadow.
MyTheme style(Updated)
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColorPrimary">@color/abc_primary_text_material_dark</item>
<item name="actionMenuTextColor">@color/abc_primary_text_material_dark</item>
<item name="android:textColorSecondary">#ffff8800</item>
<item name="android:actionBarStyle">@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse</item>
</style>
I found the solution in the Google IO app to be acceptable for myself, but saw no blog or Stackoverflow post fully explaining it. What you can do is grab their Apache 2 licensed drawer shadow asset from https://github.com/google/iosched/blob/master/android/src/main/res/drawable-xxhdpi/bottom_shadow.9.png and then in the layout of your Activity:
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:foreground="@drawable/header_shadow">
<!-- YOUR STUFF HERE -->
</FrameLayout>
</RelativeLayout>
Whereas header shadow is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="header_shadow" type="drawable">@drawable/bottom_shadow</item>
</resources>
for API levels <21. Just like https://github.com/google/iosched/blob/master/android/src/main/res/values/refs.xml and https://github.com/google/iosched/blob/master/android/src/main/res/values-v21/refs.xml.
And to be elaborate, here is toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:theme="@style/ToolbarTheme"
app:popupTheme="@style/AppTheme"/>
这篇关于安卓:Appcompat 21如何添加阴影动作条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!