AppCompatNightModeDialog.java revision b31c3281d870e9abb673db239234d580dcc4feff
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 androidx.annotation.Nullable;
20import androidx.appcompat.app.AppCompatActivity;
21import androidx.appcompat.app.AppCompatDelegate;
22import androidx.appcompat.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