android 5.0 imageButton自带阴影解决方案

满堂花醉三千客,一剑霜寒十四洲。这篇文章主要讲述android 5.0 imageButton自带阴影解决方案相关的知识,希望能为你提供帮助。
偶然发现,当android 5.0在按如下方式使用ImageButton时,会有自带的阴影,如图:

android 5.0 imageButton自带阴影解决方案

文章图片
android 5.0 imageButton自带阴影解决方案

文章图片
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > < ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="https://www.songbingjia.com/android/@drawable/ic_launcher" /> < /LinearLayout>

View Code
android 5.0 imageButton自带阴影解决方案

文章图片

解决方法就把android:src="https://www.songbingjia.com/android/@drawable/ic_launcher"改成  android:background="@drawable/ic_launcher"效果如图:
android 5.0 imageButton自带阴影解决方案

文章图片

【android 5.0 imageButton自带阴影解决方案】原因就是ImageButton继承ImageView,并加载了一个默认样式:
public ImageButton(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.imageButtonStyle);
}

    推荐阅读