2015-06-05 146 views
-4

無法更改android中的主題。我嘗試了兩件事 1.在manifest.xml中更改應用程序和活動標記。 2.改變android圖形佈局的主題。 在這兩種情況下,我的應用程序crashes.also IM使用API​​ 16在android中更改主題?

+1

發佈您的代碼PLZ –

+0

你得到什麼錯誤?併發布你的代碼。 – Kunu

+0

發佈錯誤日誌和您的清單代碼 –

回答

0

嘗試這種方式

public class EditTextSmartPhoneActivity extends Activity implements DialogInterface.OnClickListener 
{ 
    public final static int CREATE_DIALOG = -1; 
    public final static int THEME_HOLO_LIGHT = 0; 
    public final static int THEME_BLACK = 1; 

    int position; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     position = getIntent().getIntExtra("position", -1); 

     switch(position) 
     { 
     case CREATE_DIALOG: 
      createDialog(); 
      break; 
     case THEME_HOLO_LIGHT: 
      setTheme(android.R.style.Theme_Holo_Light); 
      break; 
     case THEME_BLACK: 
      setTheme(android.R.style.Theme_Black); 
      break; 
     default: 
     } 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

    } 

    private void createDialog() 
    { 
     /** Options for user to select*/ 
     String choose[] = {"Theme_Holo_Light","Theme_Black"}; 

     AlertDialog.Builder b = new AlertDialog.Builder(this); 

     /** Setting a title for the window */ 
     b.setTitle("Choose your Application Theme"); 

     /** Setting items to the alert dialog */ 
     b.setSingleChoiceItems(choose, 0, null); 

     /** Setting a positive button and its listener */ 
     b.setPositiveButton("OK",this); 

     /** Setting a positive button and its listener */ 
     b.setNegativeButton("Cancel", null); 

     /** Creating the alert dialog window using the builder class */ 
     AlertDialog d = b.create(); 

     /** show dialog*/ 
     d.show(); 
    } 

    @Override 
    public void onClick(DialogInterface dialog, int which) { 
     // TODO Auto-generated method stub 
     AlertDialog alert = (AlertDialog)dialog; 
     int position = alert.getListView().getCheckedItemPosition(); 

     finish(); 
     Intent intent = new Intent(this, EditTextSmartPhoneActivity.class); 
     intent.putExtra("position", position); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(intent); 
    } 
}