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 com.example.android.supportv7.R; 19 20import android.app.Dialog; 21import android.content.Context; 22import android.os.Bundle; 23import android.support.annotation.Nullable; 24import android.support.v4.view.WindowCompat; 25import android.support.v7.app.AppCompatActivity; 26import android.support.v7.app.AppCompatDelegate; 27import android.support.v7.app.AppCompatDialog; 28import android.view.Menu; 29import android.view.MenuItem; 30import android.view.View; 31import android.widget.Spinner; 32import android.widget.Toast; 33 34/** 35 * This demonstrates idiomatic usage of Dialog with Theme.AppCompat.DayNight 36 */ 37public class AppCompatNightModeDialog extends AppCompatActivity { 38 39 @Override 40 protected void onCreate(@Nullable Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 setContentView(R.layout.appcompat_night_mode); 43 } 44 45 public void setModeNightNo(View view) { 46 AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog); 47 dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO); 48 dialog.setTitle(R.string.dialog_title); 49 dialog.setContentView(R.layout.dialog_content); 50 dialog.show(); 51 } 52 53 public void setModeNightYes(View view) { 54 AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog); 55 dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); 56 dialog.setTitle(R.string.dialog_title); 57 dialog.setContentView(R.layout.dialog_content); 58 dialog.show(); 59 } 60 61 public void setModeNightAuto(View view) { 62 AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog); 63 dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO); 64 dialog.setTitle(R.string.dialog_title); 65 dialog.setContentView(R.layout.dialog_content); 66 dialog.show(); 67 } 68 69 70} 71