-
-
Save arturgaleno/5cca1934ed324bd2d9a7 to your computer and use it in GitHub Desktop.
Thanks, this mostly worked for me. However, the FAB was still going transparent after receiving a touch event. It seemed like it was caused by the reverse ripple affect that triggers on MotionEvent.ACTION_UP or when you held down on the button and then dragged your finger off.
I tried to just remove the ripple effect. Or somehow not trigger that animation but not knowing much about it I settled on this hack that re-tints the background, using your above code, whenever either of those things happen:
fab_newnote.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Rect rect;
if(event.getAction() == MotionEvent.ACTION_DOWN){
// Construct a rect of the view's bounds
fabRect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
} else if(event.getAction() == MotionEvent.ACTION_UP) {
fixFabBackgroundTint();
} else if(event.getAction() == MotionEvent.ACTION_MOVE){
if(!fabRect.contains(v.getLeft() + (int) event.getX(), v.getTop() + (int) event.getY())){
// User moved outside bounds
fixFabBackgroundTint();
}
}
return false;
}
});
My fixFabBackgroundTint()
method:
private void fixFabBackgroundTint() {
// A fix for https://code.google.com/p/android/issues/detail?id=183315
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) return;
// Gingerbread only
ViewCompat.setBackgroundTintList(fab_newnote, ColorStateList.valueOf(getResources().getColor(R.color.fab_background_tint)));
}
@nyanmatt Your use case isn't in my initial case, probably its related to the ColorStateList. I think if you change:
states[i] = new int[0];
colors[i] = Color.TRANSPARENT;
i++;
to:
states[i] = new int[0];
colors[i] = selectedColor;
i++;
It's could work. If you can test this, will be nice, because the issue still open, until now.
see: https://code.google.com/p/android/issues/detail?id=183315
Then, I call:
fab = new TintFloatingActionButton(context);
ViewCompat.setBackgroundTintList(fab, ContextCompat.getColorStateList(context, buttonColor));