【Android】FABの背景色を変える
FAB(Floating Action Button)の色をコードの中で変更する際、少しハマったので、備忘録。
fab = getActivity().findViewById(R.id.fab);
// 背景色を変えたい
fab.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
で変わると思ったが、変わらず。。。
で、色々と調べたらこれで変わるようだ。
fab = getActivity().findViewById(R.id.fab); // 背景色を変えたい //fab.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); fab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));
では!