AppCompatButton backgroundTint API< 21岁 [英] AppCompatButton backgroundTint API < 21

查看:141
本文介绍了AppCompatButton backgroundTint API< 21岁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在按钮上使用波纹效果. AppCompat v22.1在AppCompat着色中添加了AppCompatButton和新功能.

I want to use ripple effects on Buttons. AppCompat v22.1 added AppCompatButton and new functionalities to AppCompat tinting.

我的布局:

<android.support.v7.widget.AppCompatButton
        android:id="@+id/add_remove_button"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:backgroundTint="@color/primary"
        android:textColor="@android:color/white"
        android:text="Remove" />

在我的API 22测试设备上,波纹效果可以很好地工作,但是我正在为API 11编码,不幸的是,backgroundTint需要API> =21.如何在旧版API上将波纹效果设置为Buttons?

On my API 22 test device the ripple effect works perfectly, but i'm coding for API 11 and unfortunately backgroundTint needs API >= 21. How can i set the ripple effect to Buttons on older API versions?

推荐答案

只需使用app:backgroundTint而不是android:backgroundTint,颜色就会在棒棒糖以下生效.原因是AppCompatActivity AppCompatDelegateImplV7使用AppCompatViewInflater自动将Button或TextView更改为AppCompatButton或AppCompatTextView,然后app:backgroundTint生效.

Just use app:backgroundTint instead of android:backgroundTint, the tint will take effect below Lollipop. The reason is AppCompatActivity AppCompatDelegateImplV7 use AppCompatViewInflater to auto change Button or TextView to AppCompatButton or AppCompatTextView, then app:backgroundTint take effect.

这篇关于AppCompatButton backgroundTint API&lt; 21岁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆