Хорошо, я вставляю ваш код в мой тестовый проект (с небольшими изменениями), и он работает нормально.
FloatingActionButton fab;
int floatingActionButtonMode = 0;
public static void setButtonTint(FloatingActionButton button, ColorStateList tint) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
((TintableBackgroundView) button).setSupportBackgroundTintList(tint);
} else {
ViewCompat.setBackgroundTintList(button, tint);
}
}
public void switchFABmode(){
switch (floatingActionButtonMode){
case 0:
setButtonTint(fab,getResources().getColorStateList(R.color.colorPrimary));
floatingActionButtonMode = 1;
Toast.makeText(getActivity(), "Tap time to delete",Toast.LENGTH_SHORT).show();
break;
case 1:
setButtonTint(fab,getResources().getColorStateList(R.color.colorAccent));
Toast.makeText(getActivity(),"Tap time to share", Toast.LENGTH_SHORT).show();
floatingActionButtonMode = 0;
break;
}
}
и во фрагменте onCreateView
:
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.map, container, false);
fab = v.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switchFABmode();
}
});
return v;
}