Elevation effect for ImageButton on Pre-Lollipop devices

强颜欢笑 提交于 2019-12-12 12:11:52

问题


I am trying the apply elevation effect for ImageButton. It works well on my Nexus tablet running Android 5.0 but elevation does not work on Pre-Lollipop devices.

Tried ViewCompat.setElevation(view, evaluationValue) but nothing changed.

I saw some applications like Swarm or Gmail apps use elevation effect for their FAB (Floating Action Button) on Pre-Lollipop devices.

Do you have an idea how they use elevation?


回答1:


You cannot use elevation pre 5.0, you need to provide an image with a "shadow" to make it appear like its elevated




回答2:


It's true than you cannot do it now but for different reason.

There is a setElevation method inter support library for pre Lollipop. But I think it's buggy and still is not usable with all types of views.

Check it out here

http://developer.android.com/reference/android/support/v4/view/ViewCompat.html#setElevation(android.view.View,%20float)

Edit: sorry, I noticed now you already tried it. I hope Google has plans to fix this soon




回答3:


as mentioned in this post set background to

android:background="@android:drawable/dialog_holo_light_frame"

it looks like raised button on pre lollipop.



来源:https://stackoverflow.com/questions/27432343/elevation-effect-for-imagebutton-on-pre-lollipop-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!