It seems to me that this is a bug of Android 10 that was fixed in version 14, from a look at Volume #183315 but that appeared during version 23.0.0 of the design library.
There are two solutions, one simple and one that depends on an over-write the behavior of the FAB
.
1) Return to version 22.2.1.
Sometimes this is common (unfortunately). If there is a bug in the library, and it has no solution, simply regress if you do not use any version-specific function.
2) Create a class that inherits from FloatActionButton
of the design library as a "workaround", suggested by the commentary #9:
public class TintFloatingActionButton extends FloatingActionButton implements TintableBackgroundView {
static final int[] PRESSED_ENABLED_STATE_SET = {android.R.attr.state_pressed,
android.R.attr.state_enabled};
static final int[] FOCUSED_ENABLED_STATE_SET = {android.R.attr.state_focused,
android.R.attr.state_enabled};
private static final int[] TINT_ATTRS = {
android.R.attr.background
};
private TintInfo mBackgroundTint;
public TintFloatingActionButton(Context context) {
super(context);
}
public TintFloatingActionButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TintFloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
if (TintManager.SHOULD_BE_USED) {
TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
TINT_ATTRS, defStyleAttr, 0);
if (a.hasValue(0)) {
setSupportBackgroundTintList(createColorStateList(a.getResourceId(0, -1)));
}
a.recycle();
}
}
private static ColorStateList createColorStateList(int selectedColor) {
final int[][] states = new int[3][];
final int[] colors = new int[3];
int i = 0;
states[i] = FOCUSED_ENABLED_STATE_SET;
colors[i] = selectedColor;
i++;
states[i] = PRESSED_ENABLED_STATE_SET;
colors[i] = selectedColor;
i++;
// Default enabled state
states[i] = new int[0];
colors[i] = Color.TRANSPARENT;
i++;
return new ColorStateList(states, colors);
}
@Override
public void setSupportBackgroundTintList(ColorStateList tint) {
if (mBackgroundTint == null) {
mBackgroundTint = new TintInfo();
}
mBackgroundTint.mTintList = tint;
mBackgroundTint.mHasTintList = tint != null;
applySupportBackgroundTint();
}
@Nullable
@Override
public ColorStateList getSupportBackgroundTintList() {
return mBackgroundTint != null ? mBackgroundTint.mTintList : null;
}
@Override
public void setSupportBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) {
if (mBackgroundTint == null) {
mBackgroundTint = new TintInfo();
}
mBackgroundTint.mTintMode = tintMode;
mBackgroundTint.mHasTintMode = tintMode != null;
applySupportBackgroundTint();
}
@Nullable
@Override
public PorterDuff.Mode getSupportBackgroundTintMode() {
return mBackgroundTint != null ? mBackgroundTint.mTintMode : null;
}
private void applySupportBackgroundTint() {
if (getBackground() != null && mBackgroundTint != null) {
TintManager.tintViewBackground(this, mBackgroundTint);
}
}
}
Complete code in this gist: https://gist.github.com/arturgaleno/5cca1934ed324bd2d9a7
You are on Stack Overflow in English. The questions here are in English! Edit and translate there, Fabiano. I recommend reading the [tour].
– emanuelsn
thanks for the tip!
– Fabiano Araujo
It could include the value of
@color/colorFab
? I believe you are putting a value in the formatrrggbbaa
but the right thing isaarrggbb
, vine doc.– Wakim
I have already taken, put again, put app:backgroundTint="@color/colorPrimary", android:background="@color/colorPrimary", created an xml in drawable and put as background, but nothing changes. But in the preview of android studio works cool and in some Apis,like android 4.1, but when run in API 10, android 2.3.6, gets like this.
– Fabiano Araujo