protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var actionBar = FindViewById<ActionBar>(Resource.Id.actionbar);
            m_ActionBar = actionBar;
            m_ActionBar.CurrentActivity = this;
            actionBar.SetTitle("BingBong");

            //always put these 2 in there since they are NOT in my menu.xml
            ActionBarAction shareAction = new MyActionBarAction(this, CreateShareIntent(), Resource.Drawable.ic_title_share_default)
            {
                ActionType = ActionType.Always
            };
            actionBar.AddAction(shareAction);
            

            var otherAction = new MyActionBarAction(this, new Intent(this, typeof(OtherActivity)), Resource.Drawable.ic_title_export_default)
            {
                ActionType = ActionType.Always
            };
            actionBar.AddAction(otherAction);

            //only put in if there is room
            var searchMenuItemAction = new MenuItemActionBarAction(
                this, this, Resource.Id.menu_search,
                Resource.Drawable.ic_action_search_dark,
                Resource.String.menu_string_search)
                                           {
                                               ActionType = ActionType.IfRoom
                                           };
            actionBar.AddAction(searchMenuItemAction);
            
            //never put this guy in there
            searchMenuItemAction = new MenuItemActionBarAction(
                this, this, Resource.Id.menu_refresh,
                Resource.Drawable.ic_action_refresh_dark,
                Resource.String.menu_string_refresh)
                                       {
                                           ActionType = ActionType.Never
                                       };
            actionBar.AddAction(searchMenuItemAction);
            
            var startProgress = FindViewById<Button>(Resource.Id.start_progress);
            startProgress.Click += (s, e) => actionBar.ProgressBarVisibility = ViewStates.Visible;

            var stopProgress = FindViewById<Button>(Resource.Id.stop_progress);
            stopProgress.Click += (s, e) => actionBar.ProgressBarVisibility = ViewStates.Gone;

            var removeActions = FindViewById<Button>(Resource.Id.remove_actions);
            removeActions.Click += (s, e) => actionBar.RemoveAllActions();

            var removeShareAction = FindViewById<Button>(Resource.Id.remove_share_action);
            removeShareAction.Click += (s, e) => actionBar.RemoveAction(shareAction);
            
            var addAction = FindViewById<Button>(Resource.Id.add_action);
            addAction.Click += (s, e) =>
            {
                var action = new MyOtherActionBarAction(this, null, Resource.Drawable.ic_title_share_default);
                actionBar.AddAction(action);
            };

            var removeAction = FindViewById<Button>(Resource.Id.remove_action);
            removeAction.Click += (s, e) =>
            {
                actionBar.RemoveActionAt(actionBar.ActionCount - 1);
                Toast.MakeText(this, "Removed action.", ToastLength.Short).Show();
            };
        }
예제 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var actionBar = FindViewById<ActionBar>(Resource.Id.actionbar);
            m_ActionBar = actionBar;
            m_ActionBar.CurrentActivity = this;

            /*
             * You can also set the title of the ActionBar with: 
             * actionBar.Title = "MyAwesomeTitle";
             * 
             * or
             * 
             * actionBar.Title = Resource.String.<yourStringId>;
             * 
             * Title Color can be set with:
             * actionBar.TitleColor = Color.Blue; //Or any other Color you want
             * 
             * The Separator between the Action Bar Items can be set with:
             * actionBar.SeparatorColor = Color.Blue;
             * 
             * and with a drawable:
             * 
             * actionBar.SeparatorDrawable = myDrawable;
             */

            //always put these 2 in there since they are NOT in my menu.xml
            ActionBarAction shareAction = new MyActionBarAction(this, CreateShareIntent(), Resource.Drawable.ic_title_share_default)
            {
                ActionType = ActionType.Always
            };
            actionBar.AddAction(shareAction);
            

            var otherAction = new MyActionBarAction(this, new Intent(this, typeof(OtherActivity)), Resource.Drawable.ic_title_export_default)
            {
                ActionType = ActionType.Always
            };
            actionBar.AddAction(otherAction);

            //only put in if there is room
            var searchMenuItemAction = new MenuItemActionBarAction(
                this, this, Resource.Id.menu_search,
                Resource.Drawable.ic_action_search_dark,
                Resource.String.menu_string_search)
                                           {
                                               ActionType = ActionType.IfRoom
                                           };
            actionBar.AddAction(searchMenuItemAction);
            
            //never put this guy in there
            searchMenuItemAction = new MenuItemActionBarAction(
                this, this, Resource.Id.menu_refresh,
                Resource.Drawable.ic_action_refresh_dark,
                Resource.String.menu_string_refresh)
                                       {
                                           ActionType = ActionType.Never
                                       };
            actionBar.AddAction(searchMenuItemAction);
            
            var startProgress = FindViewById<Button>(Resource.Id.start_progress);
            startProgress.Click += (s, e) => actionBar.ProgressBarVisibility = ViewStates.Visible;

            var stopProgress = FindViewById<Button>(Resource.Id.stop_progress);
            stopProgress.Click += (s, e) => actionBar.ProgressBarVisibility = ViewStates.Gone;

            var removeActions = FindViewById<Button>(Resource.Id.remove_actions);
            removeActions.Click += (s, e) => actionBar.RemoveAllActions();

            var removeShareAction = FindViewById<Button>(Resource.Id.remove_share_action);
            removeShareAction.Click += (s, e) => actionBar.RemoveAction(shareAction);
            
            var addAction = FindViewById<Button>(Resource.Id.add_action);
            addAction.Click += (s, e) =>
            {
                var action = new MyOtherActionBarAction(this, null, Resource.Drawable.ic_title_share_default);
                actionBar.AddAction(action);
            };

            var removeAction = FindViewById<Button>(Resource.Id.remove_action);
            removeAction.Click += (s, e) =>
            {
                actionBar.RemoveActionAt(actionBar.ActionCount - 1);
                Toast.MakeText(this, "Removed action.", ToastLength.Short).Show();
            };
        }