解决Android 5.0以上版本Button自带阴影效果的方法

来源:互联网 发布:mac好玩的小游戏 编辑:程序博客网 时间:2024/05/18 00:21

今天跟UI对界面,发现一个按钮使用系统自带的button会自动有一个阴影。然而在4.x上却没有这个问题。直觉就是因为MD导致的Android版本差异。 
果断Google,在stackoverflow上找到了解决方案。 
http://stackoverflow.com/questions/28756035/how-to-remove-button-shadow-android 
关键一条代码 
style=”?android:attr/borderlessButtonStyle” 
属性解释

<Buttonandroid:id="@+id/button_send"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/button_send"android:onClick="sendMessage"style="?android:attr/borderlessButtonStyle" />
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

设置该属性就可以去掉自带的阴影。 
该属性在API 11及以上可用。鉴于现在普遍都是API 14,所以可以放心使用。已在5.1和6.0上试过,没问题。

0 0