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