forked from dotnet/android-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoneButtonActivity.cs
64 lines (53 loc) · 1.75 KB
/
DoneButtonActivity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
/**
* A sample activity demonstrating the "done button" alternative action bar presentation. For a more
* detailed description see {@link R.string.done_button_description}.
*/
namespace DoneBar
{
[Activity (Label = "DoneButtonActivity", Theme="@style/Theme.Sample")]
public class DoneButtonActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Inflate a "Done" custom action bar view to serve as the "Up" affordance.
var inflater = (LayoutInflater) ActionBar.ThemedContext.GetSystemService (Context.LayoutInflaterService);
View customActionBarView = inflater.Inflate (Resource.Layout.actionbar_custom_view_done, null);
customActionBarView.FindViewById (Resource.Id.actionbar_done).Click += delegate {
// "Done"
Finish();
};
// Show the custom action bar view and hide the normal Home icon and title.
ActionBar.SetDisplayOptions (ActionBarDisplayOptions.ShowCustom, ActionBarDisplayOptions.ShowCustom
| ActionBarDisplayOptions.ShowHome | ActionBarDisplayOptions.ShowTitle);
ActionBar.CustomView = customActionBarView;
SetContentView (Resource.Layout.activity_done_button);
}
public override bool OnCreateOptionsMenu (IMenu menu)
{
base.OnCreateOptionsMenu (menu);
MenuInflater.Inflate (Resource.Menu.cancel, menu);
return true;
}
public override bool OnOptionsItemSelected (IMenuItem item)
{
switch (item.ItemId) {
case Resource.Id.cancel:
// "Cancel"
Finish ();
return true;
}
return base.OnOptionsItemSelected (item);
}
}
}