Button设置elevation阴影
来源:互联网 发布:营销群发软件 编辑:程序博客网 时间:2024/06/06 09:58
Button设置elevation阴影没效果是因为默认主题里,已经有了elevation设置,所以再设置就没用了,可以先用android:stateListAnimator=”@null”把默认动画置空,然后再设置elevation,还要设置背景颜色,没有背景颜色是没有阴影效果的。设置完后运行效果如下图,(感谢南哥全程指导)
<Button android:id="@+id/bt_main" android:elevation="10dp" android:stateListAnimator="@null" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/holo_orange_light" android:text="Button" /> <Button android:id="@+id/bt_main1" android:elevation="10dp" android:layout_marginTop="20dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/holo_orange_light" android:text="Button1" />
可以看出已经有了阴影效果,请淡定,你这个时候再点击Button时会发现,Button按下动画效果没有了,影响到了用户体验。(感谢南哥全程指导)
按下动画问题解决:
把Button外面嵌套一层LinerLayout把elevation属性放到LinerLayout里,设置背景颜色,没有背景颜色是看不到阴影效果的。给Button一个样式style=”@style/Widget.AppCompat.Button.Borderless”
<LinearLayout android:elevation="10dp" android:layout_width="300dp" android:layout_height="100dp" android:background="#E99700"> <Button style="@style/Widget.AppCompat.Button.Borderless" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
可以看到现在点击已经有了动画效果(感谢南哥全程指导)
本文有很多不足之处,劳请各位博友留言评论,让我好借鉴完善本篇文章。
文末再次感谢南哥,你是我的榜样,是我学习的对象。
1 0
- Button设置elevation阴影
- 设置elevation后没有用,没有阴影显示
- 使用Material Design中 elevation来设置阴影失效
- Android 5.0 android:elevation 如果给button设置效果
- Android 5.0 android:elevation 如果给button设置效果
- Android 5.0 android:elevation 如果给button设置效果
- Android 5.0 android:elevation 如果给button设置效果
- Android中“android:elevation”设置阴影,在真机上没有效果的问题
- 在不使用 android:elevation 属性的情况下设置View阴影
- 设置button的圆角与 阴影
- Button 设置半圆角和阴影
- android 5.x—Elevation阴影
- 关于Android中的elevation阴影显示条件
- elevation
- android 5.0上,阴影elevation无效的问题
- android5.x中的阴影效果elevation和translationZ
- 设置阴影
- 阴影设置
- ViewPager中使用PhotoView频繁缩放导致错误
- 关于const的使用
- android 点击跳转应用市场评分页面
- Android 使用Fiddler抓取Https请求
- CodeSmith系列(三)——使用CodeSmith生成ASP.NET页面
- Button设置elevation阴影
- 《java提高数据导入效率优化思路》
- 常见问题-关闭页面
- InnoDB存储引擎MVCC实现原理
- ROS Nodehandle句柄
- java.lang.InternalError: internal error: SHA-1 not available
- UIImage的scale及size,二倍图,三倍图,像素等概念透析
- JSP指令与动作元素
- Python中斐波那契数列实现