1 /*
2  * Copyright 2013 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 
17 package com.example.android.donebar;
18 
19 import android.app.ActionBar;
20 import android.app.Activity;
21 import android.os.Bundle;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 
26 /**
27  * A sample activity demonstrating the "done bar" alternative action bar presentation. For a more
28  * detailed description see {@link R.string.done_bar_description}.
29  */
30 public class DoneBarActivity extends Activity {
onCreate(Bundle savedInstanceState)31     public void onCreate(Bundle savedInstanceState) {
32         super.onCreate(savedInstanceState);
33 
34         // BEGIN_INCLUDE (inflate_set_custom_view)
35         // Inflate a "Done/Cancel" custom action bar view.
36         final LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
37                 .getSystemService(LAYOUT_INFLATER_SERVICE);
38         final View customActionBarView = inflater.inflate(
39                 R.layout.actionbar_custom_view_done_cancel, null);
40         customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(
41                 new View.OnClickListener() {
42                     @Override
43                     public void onClick(View v) {
44                         // "Done"
45                         finish();
46                     }
47                 });
48         customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener(
49                 new View.OnClickListener() {
50                     @Override
51                     public void onClick(View v) {
52                         // "Cancel"
53                         finish();
54                     }
55                 });
56 
57         // Show the custom action bar view and hide the normal Home icon and title.
58         final ActionBar actionBar = getActionBar();
59         actionBar.setDisplayOptions(
60                 ActionBar.DISPLAY_SHOW_CUSTOM,
61                 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
62                         | ActionBar.DISPLAY_SHOW_TITLE);
63         actionBar.setCustomView(customActionBarView,
64                 new ActionBar.LayoutParams(
65                         ViewGroup.LayoutParams.MATCH_PARENT,
66                         ViewGroup.LayoutParams.MATCH_PARENT));
67         // END_INCLUDE (inflate_set_custom_view)
68 
69         setContentView(R.layout.activity_done_bar);
70     }
71 }
72