2

how can I do this color change?

Show me

Please help me, it's important...

samuelez
  • 91
  • 1
  • 1
  • 4
  • Please See this [Post](http://stackoverflow.com/questions/25815769/how-to-really-programmatically-change-primary-and-accent-color-in-android-loll) or [this post](http://stackoverflow.com/questions/2482848/how-to-change-current-theme-at-runtime-in-android) it might help You. – Alfishan Salar May 30 '16 at 07:47
  • Possible duplicate of [How change ActionBar colour when swiping between fragments (Material Design)?](http://stackoverflow.com/questions/26812554/how-change-actionbar-colour-when-swiping-between-fragments-material-design) – adneal May 30 '16 at 16:58

1 Answers1

0

setOnTabSelectedListener in add tab wise set color of statusbar,toolbar & tablayout Like this...

tablayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            if(tab.getPosition()==0){
                toolbar.setBackgroundColor(ContextCompat.getColor(HomeScreen.this,
                        android.R.color.darker_gray));
                tablayout.setBackgroundColor(ContextCompat.getColor(HomeScreen.this,
                        android.R.color.darker_gray));
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    getWindow().setStatusBarColor(ContextCompat.getColor(HomeScreen.this,
                            android.R.color.darker_gray));
                }
            }
            else if(tab.getPosition()==1){
                toolbar.setBackgroundColor(ContextCompat.getColor(HomeScreen.this,
                        android.R.color.holo_blue_dark));
                tablayout.setBackgroundColor(ContextCompat.getColor(HomeScreen.this,
                        android.R.color.holo_blue_dark));
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    getWindow().setStatusBarColor(ContextCompat.getColor(HomeScreen.this,
                            android.R.color.holo_blue_dark));
                }
            }
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    });

I hope this is helpful...