1 /*
2  * Copyright 2019 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 package com.example.androidx.app;
17 
18 import android.graphics.drawable.ColorDrawable;
19 import android.os.Bundle;
20 import android.view.View;
21 
22 import androidx.appcompat.app.ActionBar;
23 import androidx.appcompat.app.AppCompatActivity;
24 
25 import com.example.androidx.R;
26 
27 /**
28  * This demonstrates changing background and elevation (on supported platforms) of ActionBar.
29  */
30 public class ActionBarBackgroundChange extends AppCompatActivity {
31     @Override
onCreate(Bundle savedInstanceState)32     protected void onCreate(Bundle savedInstanceState) {
33         super.onCreate(savedInstanceState);
34         setContentView(R.layout.action_bar_background_change);
35 
36         final ActionBar actionBar = getSupportActionBar();
37         actionBar.setBackgroundDrawable(new ColorDrawable(0x00FFFFFF));
38 
39         findViewById(R.id.make_bg_transparent).setOnClickListener(
40                 new View.OnClickListener() {
41                     @Override
42                     public void onClick(View view) {
43                         actionBar.setBackgroundDrawable(new ColorDrawable(0x00FFFFFF));
44                         actionBar.setElevation(0);
45                     }
46                 });
47 
48         findViewById(R.id.make_bg_color).setOnClickListener(
49                 new View.OnClickListener() {
50                     @Override
51                     public void onClick(View view) {
52                         actionBar.setBackgroundDrawable(new ColorDrawable(0xFF80FFA0));
53                         actionBar.setElevation(20);
54                     }
55                 });
56     }
57 }
58