首页 > 移动平台 > 详细

android 5.0 imageButton自带阴影解决方案

时间:2016-10-18 22:33:31      阅读:241      评论:0      收藏:0      [点我收藏+]

偶然发现,当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="@drawable/ic_launcher" />

</LinearLayout>
View Code

技术分享

解决方法就把android:src="@drawable/ic_launcher"改成 android:background="@drawable/ic_launcher"效果如图:

技术分享

原因就是ImageButton继承ImageView,并加载了一个默认样式:

public ImageButton(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.imageButtonStyle);
}

android 5.0 imageButton自带阴影解决方案

原文:http://www.cnblogs.com/sharkli/p/5974831.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!