Android 工具栏按钮阴影

标签 android xml android-layout android-actionbar android-toolbar

我将这个半透明的渐变背景添加到工具栏,这样按钮在任何背景上都很明显,但我想知道如何在按钮本身下方制作阴影而不是我所做的?

enter image description here

谢谢

编辑

所以我意识到最简单的方法是设置 Drawable Resources。

getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_home); 

 <style name="AppTheme" parent="parent_theme">
    <item name="actionModeShareDrawable">@drawable/ic_share</item>
</style>

我下载了 Material Vector 资源,在 Adob​​e Illustrator 中添加了阴影,并将其导入到 PNG。但是 Android Studio 的图像 Assets /操作栏和选项卡图标搞砸了我不明白为什么 - 它删除了阴影,即使使用自定义“主题”颜色也不同所以我自己做了不同的 dpi 图像大小,这就是我得到。这正是我想要的

http://imgur.com/vnR98H5

最佳答案

好吧,我不知道如何用简单的按钮来做,如果你可以用 FloatingActionButton 改变 Button 你可以使用 elevation用于制作阴影。

Floating Action Button (FAB) is simply a circle button with some drop shadow that unbelieveably could change the world of design. No surprise why it becomes a signature of Material Design. So let's start with this thing. Add FAB in layout file with FloatingActionButton and wrap it with FrameLayout since it needs some parent to make it aligned at bottom right position of the screen.

The shadow depth is automatically set to the best practices one, 6dp at idle state and 12dp at pressed state. Anyway you are allowed to override these values by defining app:elevation for idle state's shadow depth and app:pressedTranslationZ for press state's.

From: http://inthecheesefactory.com/blog/android-design-support-library-codelab/en

当然,您可以通过添加图标进行自定义。我很确定,按钮上的 play 图标在 Material Design 库中。

您也可以在这里获取:https://design.google.com/icons/

为了继续,我建议您学习更多关于 FloatingActionButton 的知识,它可以让您添加一些不错的效果,例如高程/阴影和 Material 库中的其他好东西。

希望它能让你的开发更简单,让你的应用更漂亮。

关于Android 工具栏按钮阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34597081/

相关文章:

java - Recyclerview初始位置

java - 从 Parse 检索数据

java - Android 中的 ACTION_TIME_TICK 问题

android - Android 上的实时通话转录

java - "Fatal Error"以下 nutch 教程 "markup in the document following the root must be well formed"

java - 用于查找具有给定名称(例如 "//nodeName")的所有节点的标准 xpath 语法失败

java - 不幸的是,声明按钮时模拟器出错

android-layout - 原生 UI 组件 - Android View 更新时刷新

android - onItemCheckedStateChanged() 在自定义 ExpandableListView 上只调用一次

android - 来自 fetchUuidsWithSdp 的奇怪 UUID 反转