1/* 2 * Copyright (C) 2015 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 */ 16 17package com.example.android.supportv7.app; 18 19 20import android.os.Bundle; 21import android.view.View; 22 23import androidx.annotation.Nullable; 24import androidx.appcompat.app.AppCompatActivity; 25import androidx.appcompat.app.AppCompatDelegate; 26 27import com.example.android.supportv7.R; 28 29/** 30 * This demonstrates idiomatic usage of AppCompatActivity with Theme.AppCompat.DayNight 31 */ 32public class AppCompatNightModeActivity extends AppCompatActivity { 33 34 @Override 35 protected void onCreate(@Nullable Bundle savedInstanceState) { 36 super.onCreate(savedInstanceState); 37 setContentView(R.layout.appcompat_night_mode); 38 } 39 40 public void setModeNightNo(View view) { 41 getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO); 42 } 43 44 public void setModeNightYes(View view) { 45 getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); 46 } 47 48 public void setModeNightAuto(View view) { 49 getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO); 50 } 51}