I have fragments, and when I click on any fragment in the upper part of the panel (where the clock is) the color should change. How to implement?
public class MainPagerAdapter extends FragmentStatePagerAdapter { private final static int COUNT = 3; private final static int HORIZONTAL = 0; private final static int TWO_WAY = 1; private final static int TWO_WAY1 = 2; public MainPagerAdapter(final FragmentManager fm) { super(fm); } @Override public Fragment getItem(final int position) { switch (position) { case TWO_WAY: return new HorizontalPagerFragment_bookmarks(); case TWO_WAY1: return new HorizontalPagerFragment_exit(); case HORIZONTAL: return new HorizontalPagerFragment(); default: } return getItem(position); } @Override public int getCount() { return COUNT; } }
public class HorizontalPagerFragment_bookmarks extends Fragment {
@Nullable @Override public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { setStatusBarColor(R.color.colorAccent); return inflater.inflate(R.layout.fragment_horizontal1, container, false); } public void setStatusBarColor(int color) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return; } Window window = getActivity().getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(ContextCompat.getColor(getActivity(), color)); } }