First, see
:
Step 1: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.bkjia.com/uploadfile/Collfiles/20131231/20131231094620132.jpg" width = "200" height = "200" vspace = "3" hspace = "3" alt = "\">
Code:
Step 2:
Code:
Package com. example. teststyletheme; import android. OS. bundle; import android. annotation. suppressLint; import android. app. activity; import android. view. view; import android. view. view. onClickListener; import android. widget. button; @ SuppressLint ("NewApi") public class MainActivity extends Activity implements OnClickListener {Button dayBtn, nightBtn; private int THEMEID =-1; // set the topic id @ Overrideprotected void onC Reate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); if (savedInstanceState! = Null) {if (savedInstanceState. getInt ("theme",-1 )! =-1) {THEMEID = savedInstanceState. getInt ("theme"); this. setTheme (THEMEID); // set the topic skin} setContentView (R. layout. activity_main); dayBtn = (Button) findViewById (R. id. day); maid = (Button) findViewById (R. id. night); dayBtn. setOnClickListener (this); nightBtn. setOnClickListener (this);} // set the topic and recreate the private void onTheme (int iThemeId) {THEMEID = iThemeId; this. recreate ();} // Save the topic ID. When onCreate is used, the topic @ Overridepublic void onSaveInstanceState (Bundle outState) {super. onSaveInstanceState (outState); outState. putInt ("theme", THEMEID) ;}@ Overridepublic void onClick (View v) {switch (v. getId () {case R. id. day: onTheme (R. style. day_theme); // onTheme (android. r. style. theme_Holo_Light); break; case R. id. night: onTheme (R. style. night_theme); break ;}}}
The layout code is attached: