AppCompatNightModeDialog.java revision 27644c071b7fc0e1e4f91194f2a08b4aa2cf1465
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package com.example.android.supportv7.app; 17 18import android.os.Bundle; 19import android.support.annotation.Nullable; 20import android.support.v7.app.AppCompatActivity; 21import android.support.v7.app.AppCompatDelegate; 22import android.support.v7.app.AppCompatDialog; 23import android.view.View; 24 25import com.example.android.supportv7.R; 26 27/** 28 * This demonstrates idiomatic usage of Dialog with Theme.AppCompat.DayNight 29 */ 30public class AppCompatNightModeDialog extends AppCompatActivity { 31 32 @Override 33 protected void onCreate(@Nullable Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 setContentView(R.layout.appcompat_night_mode); 36 } 37 38 public void setModeNightNo(View view) { 39 AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog); 40 dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO); 41 dialog.setTitle(R.string.dialog_title); 42 dialog.setContentView(R.layout.dialog_content); 43 dialog.show(); 44 } 45 46 public void setModeNightYes(View view) { 47 AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog); 48 dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); 49 dialog.setTitle(R.string.dialog_title); 50 dialog.setContentView(R.layout.dialog_content); 51 dialog.show(); 52 } 53 54 public void setModeNightAuto(View view) { 55 AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog); 56 dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO); 57 dialog.setTitle(R.string.dialog_title); 58 dialog.setContentView(R.layout.dialog_content); 59 dialog.show(); 60 } 61 62 63} 64