2017-04-20 212 views
0

這是非常奇怪的,我有一個timePicker在我的自定義對話框中,問題是它的一些版本的android看起來不錯,但在android 5.0.2中,它獲得了黑色背景顏色是這樣的:android - 自定義對話框更改視圖背景顏色

enter image description here

,你可以看到,時鐘背景改變,但我不需要做任何改變。

final Dialog dialog = new Dialog(SabadKharid_s1.this, R.style.DialogStyler2); 
      dialog.setContentView(R.layout.dialogtime); 

      timePicker = (TimePicker) dialog.findViewById(R.id.timePicker); 
      timePicker.setIs24HourView(true); 
      WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
      lp.copyFrom(dialog.getWindow().getAttributes()); 
      lp.width = WindowManager.LayoutParams.MATCH_PARENT; 
      lp.height = WindowManager.LayoutParams.WRAP_CONTENT; 
      dialog.show(); 
      dialog.getWindow().setAttributes(lp); 

這是我的風格使用方法:

   <style name="DialogStyler2" parent="Theme.AppCompat.Light.Dialog.Alert"> 
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> 
    <item name="android:windowNoTitle">true</item> 
</style> 

我怎樣才能解決這個問題?

+0

嘗試http://www.materialdoc.com/time-pickers/ –

回答

0

你在屏幕上彈出什麼......對話可能有一個默認的主題。 嘗試使用自定義主題爲您的彈出窗口...它會改變背景顏色或設置自定義視圖彈出和在佈局設置父背景爲android:background="@andrid:color/transparent"

0

我想不出你爲什麼使用時間在對話框中你可以直接使用Material Time Pickers

您可以使用這個更簡單的解決方案。 https://github.com/wdullaer/MaterialDateTimePicker

TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(
      new TimePickerDialog.OnTimeSetListener() { 
       @Override 
       public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) { 
        //Do your thing 
    ); 
    timePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { 
     @Override 
     public void onCancel(DialogInterface dialogInterface) { 
      //do your thing for cancel event 
     } 
    }); 
    timePickerDialog.setAccentColor(ContextCompat.getColor(mContext, R.color.colorPrimary)); 

    timePickerDialog.show(getFragmentManager(), TAG); 
0

嘗試使用TimePickerDialog

// Initialize time picker 
    Calendar c = Calendar.getInstance(); 
    int curHour = c.get(Calendar.HOUR_OF_DAY); 
    int curMinute = c.get(Calendar.MINUTE); 
    boolean is24HourView = true; 

    // Construct time picker dialog 
    TimePickerDialog dialogTimePicker = new TimePickerDialog(this, 
      new TimePickerDialog.OnTimeSetListener() { 

       @Override 
       public void onTimeSet(TimePicker view, int hourOfDay, int minute) 
       { 

        // Do something 
       } 
      }, curHour, curMinute, is24HourView); 


    // Show time picker dialog 
    dialogTimePicker.setTitle("Time Picker"); 
    dialogTimePicker.show(); 

希望這將有助於〜