您可以參考下面的代碼來獲取timepicker風格。
MainActivity.java
import static android.R.attr.button;
public class MainActivity extends AppCompatActivity {
Calendar calendar ;
Button button;
TimePickerDialog timePickerDialog ;
int CalendarHour, CalendarMinute;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
calendar = Calendar.getInstance();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CalendarHour = calendar.get(Calendar.HOUR_OF_DAY);
CalendarMinute = calendar.get(Calendar.MINUTE);
timePickerDialog = new TimePickerDialog(MainActivity.this, R.style.DialogTheme,new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
Toast.makeText(MainActivity.this, "Time Selected"+selectedHour+":"+selectedMinute, Toast.LENGTH_SHORT).show();
}
}, CalendarHour, CalendarMinute, true);//Yes 24 hour time
timePickerDialog.setTitle("Select Time");
timePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
Toast.makeText(MainActivity.this, "Time Not Selected", Toast.LENGTH_SHORT).show();
}
});
timePickerDialog.show();
}
});
}
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CLICK HERE TO SHOW TIME PICKER DIALOG WITH MATERIAL DESIGN THEME"
android:id="@+id/button"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Style.xml
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/purple</item>
<item name="colorControlNormal">@color/orange</item>
</style>
我覺得你的對話框的背景色爲白色,因爲'<項目名稱= 「機器人:背景」> #FFFFFF'。嘗試將其改爲另一種顏色 –