0

I need to create a switchbutton in one activity that will change the background and words colors in all other activities.

I tried create an activity to work like a master page, whatever is change there will change in all activitys, bur didn’t work properly.

Any ideas to make a switchbutton do that will be helpful.

This was my try on the master page:

public class MainActivity extends Activity {   boolean iscolor = true;
    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btn = (Button) findViewById(R.id.btn);
        final LinearLayout layout = (LinearLayout) 
        findViewById(R.id.LinearLayout1);

        btn.setOnClickListener(new OnClickListener() {

           @Override
           public void onClick(View view) {

               if(iscolor)
               {
                   layout.setBackgroundColor(Color.BLUE);
                   iscolor = false;
               }
               else
               {
                   layout.setBackgroundColor(Color.WHITE);
                   iscolor = true;
               }

           }
      }); 
}
Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
  • Welcome to stackoverflow!! Please add some code that shows your efforts and point out where you got stuck. – mukesh kudi Sep 28 '18 at 11:45
  • You need to define both themes in styles file. Check this link https://stackoverflow.com/questions/2482848/how-to-change-current-theme-at-runtime-in-android – Sreedev P R Sep 28 '18 at 12:31

0 Answers0