偶然發現,當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>
解決方法就把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);
}