2013-04-10 127 views
4

我喜歡更改DatePicker對話框的顏色。我加載對話框爲如何更改DatePicker對話框的顏色

@SuppressLint("NewApi") 
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { 

     @SuppressLint("NewApi") 
    @Override 
     public Dialog onCreateDialog(Bundle savedInstanceState) { 
      // Use the current date as the default date in the picker 
      final Calendar c = Calendar.getInstance(); 
      int year = c.get(Calendar.YEAR); 
      int month = c.get(Calendar.MONTH); 
      int day = c.get(Calendar.DAY_OF_MONTH); 

      // Create a new instance of DatePickerDialog and return it 
      return new DatePickerDialog(getActivity(), this, year, month, day); 
     } 

     public void onDateSet(DatePicker view, int year, int month, int day) { 
      // Do something with the date chosen by the user 


     } 


} 

@SuppressLint("NewApi") 
public void showDatePickerDialog(View v) { 
    DialogFragment newFragment = new DatePickerFragment(); 
    newFragment.show(getFragmentManager(), "datePicker");//show(getSupportFragmentManager(), "datePicker"); 
} 

當它加載對話框時,它是白色背景。如何更改爲顯示第二張圖片中顯示的顏色? 謝謝enter image description hereenter image description here

+0

結帳這裏的答案 - http://stackoverflow.com/questions/6729697/set-android-theme-light-for-alert-dialog – 2013-04-10 13:19:21

+0

一個使用AlertDialog.Builder建設者=新AlertDialog.Builder( 新ContextThemeWrapper (context,R.style.popup_theme));並改變主題。但對我來說,我使用newFragment.show(getFragmentManager(),「datePicker」);我怎樣才能改變主題? – Bryanyan 2013-04-10 13:27:42

回答

3

這是我會嘗試。對於Android < = 2.3(API 10/v10),將主題從Android 3.0(API 11/v11)中的默認Android輕量級主題延伸出來,我將從holo light主題延伸。你可以看到如何在這裏做到這一點: How to use Holo.Light theme, and fall back to 'Light' on pre-honeycomb devices?

我不是100%肯定這會改變你的警告對話框,因爲我沒有使用過光的主題廣泛,所以你可能需要編輯的屬性或兩個從輕的主題到獲得編輯文本的背景變得輕鬆。

6

根據您的查詢,您必須創建自定義對話框主題並設置在custom_theme.xml現在只需根據您的API版本進行設置即可。

首先,在值增加的themes.xml這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="MyAppTheme" parent="@android:style/Theme.Light.NoTitleBar"> 
     <!-- Any customizations for your app running on pre-3.0 devices here --> 
    </style> 
</resources> 

然後,創建於res目錄名稱「值-V11」(Android 3.0以上版本)的目錄,並把一個主題。這樣

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="MyAppTheme" parent="@android:style/Theme.Holo.Light"> 
     <!-- Any customizations for your app running on 3.0+ devices here --> 
    </style> 
</resources> 

最後的XML,創建一個目錄,在res目錄名稱 「值-V14」(Android 4.0以上版本),並創建一個的themes.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="MyAppTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar"> 
     <!-- Any customizations for your app running on 4.0+ devices here --> 
    </style> 
</resources> 

For More Details查看鏈接並關注它。

希望你對他們有一些想法並解決你的問題。

祝你好運。

+1

感謝chintan khetiya你的鏈接幫了我很多.. – Venkat 2013-05-04 10:51:56

+1

請接受:P – 2013-05-04 10:53:09

相關問題