我正在尝试使用
android:background="?android:attr/selectableItemBackground"
让我的按钮为每个 android 版本做适当的效果,比如涟漪等。
但是当我需要不同的颜色时,这会产生一个灰色的按钮。
如何覆盖这个默认颜色?
最佳答案
如果您阅读 source code of Button.java然后你会看到它是 TextView.java 的子类.我已经针对相关问题做了一个简单的解决方法。
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:background="#1f5050">
<TextView android:layout_width="some_dp"
android:layout_height="some_dp"
android:id="@+id/button"
android:background="?android:selectableItemBackground" />
</LinearLayout>
在代码中:
button.setOnClickLisetener(new Onclicklistener() {
// do your stuff here
}
如果有人可以扩展 TextView 类并使用相关功能制作自定义按钮会更好。
注意:我的 minsdk 是 14。而且, Lollipop 涟漪效果也很好
关于android - 在使用 selectableItemBackground 属性时为按钮背景使用自定义颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27415056/