[{"data":1,"prerenderedAt":267},["ShallowReactive",2],{"article-xamarin-android-actionbar":3},{"article":4,"tags":97,"previous":112,"next":207},{"id":5,"title":6,"author":7,"body":8,"createdAt":86,"description":87,"extension":88,"img":26,"meta":89,"navigation":90,"path":91,"seo":92,"stem":93,"tags":94,"updatedAt":86,"__hash__":96},"articles\u002Farticles\u002Fxamarin-android-actionbar.md","Xamarin Android ActionBar","[object Object]",{"type":9,"value":10,"toc":82},"minimark",[11,34,41,44,48,51,55],[12,13,14,15,18,31,33],"p",{},"Ok so in prior posts I talked about adding drawer layout to my android project.  Today, I am going to add an actionbar to the project.  Starting with the end result of my first attempt see below.  I have an activity with tabs on each view.",[16,17],"br",{},[19,20,22],"a",{"href":21},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin_a3b5-image_2.png",[23,24],"img",{"style":25,"src":26,"border":27,"alt":28,"title":28,"width":29,"height":30},"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;","\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin_a3b5-image_thumb.png",0,"image",151,240,[16,32],{},"\nThis is how that was accomplished.  Within the OnCreate(Bundle bundle) method of the Activity",[35,36,40],"pre",{"className":37},[38,39],"brush:","csharp;","this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;              \nAddTab(\"Tab 1\", Resource.Drawable.ic_tab_white, new SampleTabFragment());  \nAddTab(\"Tab 2\", Resource.Drawable.ic_tab_white, new SampleTabFragment2());  \n  \nif (bundle != null)     this.ActionBar.SelectTab(this.ActionBar.GetTabAt(bundle.GetInt(\"tab\")));",[12,42,43],{},"Adding method AddTab",[35,45,47],{"className":46},[38,39],"        void AddTab(string tabText, int iconResourceId, Fragment view)  \n        {  \n            var tab = this.ActionBar.NewTab();  \n            tab.SetText(tabText);  \n            tab.SetIcon(Resource.Drawable.ic_tab_white);  \n  \n            \u002F\u002F must set event handler before adding tab  \n  \n            tab.TabSelected += delegate (object sender, Android.App.ActionBar.TabEventArgs e)  \n            {  \n                var fragment = this.FragmentManager.FindFragmentById(Resource.Id.frameLayout);  \n                if (fragment != null)  \n                    e.FragmentTransaction.Remove(fragment);  \n                e.FragmentTransaction.Add(Resource.Id.frameLayout, view);  \n            };  \n            tab.TabUnselected += delegate (object sender, Android.App.ActionBar.TabEventArgs e) {  \n                e.FragmentTransaction.Remove(view);  \n            };  \n  \n            this.ActionBar.AddTab(tab);  \n        }",[12,49,50],{},"Adding fragment classes for the end target for selecting a tab",[35,52,54],{"className":53},[38,39],"    public class SampleTabFragment : Fragment  \n    {  \n        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)  \n        {  \n            base.OnCreateView(inflater, container, savedInstanceState);  \n  \n            var view = inflater.Inflate(Resource.Layout.Tab, container, false);  \n            var sampleTextView = view.FindViewById\u003CTextView>(Resource.Id.sampleTextView);  \n            sampleTextView.Text = \"sample fragment text\";  \n  \n            return view;  \n        }  \n    }  \n  \n    public class SampleTabFragment2 : Fragment  \n    {  \n        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)  \n        {  \n            base.OnCreateView(inflater, container, savedInstanceState);  \n  \n            var view = inflater.Inflate(Resource.Layout.Tab, container, false);  \n            var sampleTextView = view.FindViewById\u003CTextView>(Resource.Id.sampleTextView);  \n            sampleTextView.Text = \"sample fragment text 2\";  \n  \n            return view;  \n        }  \n    }",[12,56,57,58,60,61,65,67,68,70,71,73],{},"When a user selects a tab, we have them hooked up to show the respective fragment.  I also noticed that the code within the TabSelected event could be replaced by the following FragmentManager code",[16,59],{},"\ntab.TabSelected += delegate (object sender, Android.App.ActionBar.TabEventArgs e) { \u002F\u002Fvar fragment = this.FragmentManager.FindFragmentById(Resource.Id.frameLayout); \u002F\u002Fif (fragment != null) \u002F\u002Fe.FragmentTransaction.Remove(fragment); \u002F\u002Fe.FragmentTransaction.Add(Resource.Id.frameLayout, view);    ",[62,63,64],"strong",{}," base.FragmentManager.BeginTransaction().Replace(Resource.Id.frameLayout, view).Commit(",[16,66],{},"\n};",[16,69],{},"\nWhile the above works to show tabs in my sample application this is not really what I am looking for. The following guide shows the different aspects of the ActionBar.  In our above example we were working with Tab Navigation.  Ideally, what I am looking for is how to get my tabs where the action buttons are shown.",[16,72],{},[19,74,76],{"href":75},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin_a3b5-image_4.png",[23,77],{"style":78,"src":79,"border":27,"alt":28,"title":28,"width":80,"height":81},"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;","\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin_a3b5-image_thumb_1.png",290,279,{"title":83,"searchDepth":84,"depth":84,"links":85},"",2,[],"2016-02-06T08:02:02.1700000-05:00","More fun with actionbars with Xamarin","md",{},true,"\u002Farticles\u002Fxamarin-android-actionbar",{"title":6,"description":87},"articles\u002Fxamarin-android-actionbar",[95],"xamarin","D9kSu3OBx2kAPQJfH-P1Y6pJDljKlYK_lEnLxL0fRJM",[98],{"id":99,"title":100,"body":101,"description":105,"extension":88,"img":106,"meta":107,"name":95,"navigation":90,"path":108,"seo":109,"stem":110,"__hash__":111},"tags\u002Ftags\u002Fxamarin.md","Xamarin",{"type":9,"value":102,"toc":103},[],{"title":83,"searchDepth":84,"depth":84,"links":104},[],"Xamarin is an open-source platform for building modern and performant applications for iOS, Android, and Windows with . NET. Xamarin is an abstraction layer that manages communication of shared code with underlying platform code.","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"\u002Ftags\u002Fxamarin",{"description":105},"tags\u002Fxamarin","deVB66I7cJMtWvqybFh5POf9LBCBwHNe-5ZGMOzV5G4",{"id":113,"title":114,"author":7,"body":115,"createdAt":199,"description":200,"extension":88,"img":174,"meta":201,"navigation":90,"path":202,"seo":203,"stem":204,"tags":205,"updatedAt":199,"__hash__":206},"articles\u002Farticles\u002Fxamarin-please-install-package-android-support-library.md","Xamarin Please install package ‘Android Support Library’",{"type":9,"value":116,"toc":197},[117,120,158,177,185,193],[12,118,119],{},"  My Xamarin Android project would not build.  The build output had the following exception\u002Ferror.\nSeverity Code Description Project File Line Suppression State Error",[35,121,125],{"className":122,"code":123,"language":124,"meta":83,"style":83},"language-html shiki shiki-themes github-light github-dark","Please install package: 'Xamarin.Android.Support.v4' available in SDK installer. \nAndroid resource directory C:\\Users\\{username}\\AppData\\Local\\Xamarin\\Android.Support.v4\\22.2.0\\embedded\\.\u002F doesn't exist.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \nC:\\Program Files (x86)\\MSBuild\\Xamarin\\Android\\Xamarin.Android.Common.targets 349&nbsp;&nbsp;&nbsp;  \n","html",[126,127,128,137,149],"code",{"__ignoreMap":83},[129,130,133],"span",{"class":131,"line":132},"line",1,[129,134,136],{"class":135},"sVt8B","Please install package: 'Xamarin.Android.Support.v4' available in SDK installer. \n",[129,138,139,142,146],{"class":131,"line":84},[129,140,141],{"class":135},"Android resource directory C:\\Users\\{username}\\AppData\\Local\\Xamarin\\Android.Support.v4\\22.2.0\\embedded\\.\u002F doesn't exist.",[129,143,145],{"class":144},"sj4cs","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",[129,147,148],{"class":135}," \n",[129,150,152,155],{"class":131,"line":151},3,[129,153,154],{"class":135},"C:\\Program Files (x86)\\MSBuild\\Xamarin\\Android\\Xamarin.Android.Common.targets 349",[129,156,157],{"class":144},"&nbsp;&nbsp;&nbsp;\n",[12,159,160,161,167,168],{},"I started to get this error after adding the component Android Support Library v7 AppCompat (version 22.2.0.0) This component has dependencies on Xamarin.Android.Support.v4.\nAfter much time and looking at Android SDK’s ",[62,162,163],{},[164,165,166],"u",{},"the resolution"," was to remove the respective zip file from this directory\nC:\\Users{username}\\AppData\\Local\\Xamarin\\zips. Once I did this, a fresh build would re-download this package and unzip appropriate references\nto C:\\Users{username}\\AppData\\Local\\Xamarin.  In addition you can delete everything in the C:\\Users{username}\\AppData\\Local\\Xamarin\\Android.Support.v4 directory.\n",[19,169,171],{"href":170},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-245aeb9a3723_fde8-image_6.png",[23,172],{"title":28,"style":173,"border":27,"alt":28,"src":174,"width":175,"height":176},"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px","\u002Farticles\u002Fimages\u002Fwindows-live-writer-245aeb9a3723_fde8-image_thumb_2.png",294,88,[19,178,180],{"href":179},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-245aeb9a3723_fde8-image_4.png",[23,181],{"title":28,"style":173,"border":27,"alt":28,"src":182,"width":183,"height":184},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-245aeb9a3723_fde8-image_thumb_1.png",411,50,[19,186,188],{"href":187},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-245aeb9a3723_fde8-image_2.png",[23,189],{"title":28,"style":173,"border":27,"alt":28,"src":190,"width":191,"height":192},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-245aeb9a3723_fde8-image_thumb.png",417,233,[194,195,196],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":83,"searchDepth":84,"depth":84,"links":198},[],"2016-02-06T12:29:47.8100000-05:00",null,{},"\u002Farticles\u002Fxamarin-please-install-package-android-support-library",{"title":114,"description":200},"articles\u002Fxamarin-please-install-package-android-support-library",[95],"8pRh1b0XfQH5mWwb5lohfycB3F0kfUGsZ2iKu_RUjUQ",{"id":208,"title":209,"author":7,"body":210,"createdAt":260,"description":214,"extension":88,"img":255,"meta":261,"navigation":90,"path":262,"seo":263,"stem":264,"tags":265,"updatedAt":260,"__hash__":266},"articles\u002Farticles\u002Fxamarin-android-listviews-part-2-of-2.md","Xamarin Android - ListViews Part 2 of 2",{"type":9,"value":211,"toc":258},[212,215,220,226,230,236,244],[12,213,214],{},"Continuing on from an older post, we will modify our listview to display 2 columns.  Ultimately, we will put an image in the left column and text in the right column.  Currently we have created an ArrayAdapter which takes a list\u002Fcollection of strings and displays each row in a template.  The template was defined in a layout TextViewItem.axml",[35,216,219],{"className":217},[38,218],"xml;","\u003C?xml version=\"1.0\" encoding=\"utf-8\"?>  \n\u003CTextView xmlns:android=\"http:\u002F\u002Fschemas.android.com\u002Fapk\u002Fres\u002Fandroid\"  \n    android:id=\"@+id\u002FtextItem\"  \n    android:textSize=\"44sp\"  \n    android:layout_width=\"fill_parent\"  \n    android:layout_height=\"wrap_content\" \u002F>",[12,221,222,223,225],{},"What we have was an ArrayAdapter which required the above row definition with a collection of strings.  This worked fine to display the ToString() of either the string collection you provided or the object collection you used in the definition.",[16,224],{},"\nMoving forward this post will use a more advanced row template to display a string or an object collection.  This ultimately gives us more flexibility.  To do this we will create a custom Adapter which manages the displays aspect of the listview.  By doing this we can provide a collection of objects and then through our custom adapter we can position each property within our new row template.  Our new row template TextViewItem2.axml will be defined by the following.",[35,227,229],{"className":228},[38,218],"\u003C?xml version=\"1.0\" encoding=\"utf-8\"?>  \n\u003CLinearLayout xmlns:android=\"http:\u002F\u002Fschemas.android.com\u002Fapk\u002Fres\u002Fandroid\"  \n    android:orientation=\"vertical\"  \n    android:layout_width=\"match_parent\"  \n    android:layout_height=\"match_parent\"  \n    android:minWidth=\"25px\"  \n    android:minHeight=\"25px\">  \n    \u003CLinearLayout  \n        android:orientation=\"horizontal\"  \n        android:minWidth=\"25px\"  \n        android:minHeight=\"25px\"  \n        android:layout_width=\"match_parent\"  \n        android:layout_height=\"wrap_content\"  \n        android:id=\"@+id\u002FlinearLayout1\">  \n        \u003CTextView  \n            android:id=\"@+id\u002FtextItem1\"  \n            android:textSize=\"44sp\"  \n            android:layout_width=\"wrap_content\"  \n            android:layout_height=\"fill_parent\" \u002F>  \n        \u003CTextView  \n            android:id=\"@+id\u002FtextItem2\"  \n            android:textSize=\"44sp\"  \n            android:layout_width=\"wrap_content\"  \n            android:layout_height=\"fill_parent\" \u002F>  \n    \u003C\u002FLinearLayout>  \n\u003C\u002FLinearLayout>",[12,231,232,233,235],{},"Here you can see we have a LinearLayout parent and a LinearLayout (horizontal orientation) established to display 2 textviews side by side.",[16,234],{},"\nNow to the adapter, as mentioned above we have to build out a custom adapter as this adapter will be responsible for take each item in our collection and mapping our object properties to specific controls in the above textviewitem template.",[35,237,239,240,243],{"className":238},[38,39],"   public class AboutScreenAdapter : BaseAdapter\u003CMyDetail>  \n    {  \n        List\u003CMyDetail> _items;  \n        Activity _context;  \n        public AboutScreenAdapter(Activity context, List\u003CMyDetail> items) : base()  \n        {  \n            this._context = context;  \n            this._items = items;  \n        }  \n        public override long GetItemId(int position)  \n        {  \n            return position;  \n        }  \n        public override MyDetail this[int position]  \n        {  \n            get { return _items[position]; }              \n        }  \n  \n        public override int Count  \n        {  \n            get { return _items.Count; }  \n        }  \n        public override View GetView(int position, View convertView, ViewGroup parent)  \n        {  \n            View view = convertView; \u002F\u002F re-use an existing view, if one is available  \n            if (view == null) \u002F\u002F otherwise create a new one  \n                view = _context.LayoutInflater.Inflate(Resource.Layout.",[62,241,242],{},"TextViewItem2",", null);  \n              \n            \u002F\u002Fview.FindViewById\u003CTextView>(Android.Resource.Id.text).Text = items[position];  \n  \n            view.FindViewById\u003CTextView>(Resource.Id.textItem1).Text = _items[position].Image;  \n            view.FindViewById\u003CTextView>(Resource.Id.textItem2).Text = _items[position].Detail;  \n            return view;  \n        }  \n    }",[12,245,246,247,249],{},"Above you can see, we provide our object collection List\u003CMyDetail> items and the row template is defined (bold) TextViewItem2 which is established by a layout in our layouts folder TextViewItem2.axml",[16,248],{},[19,250,252],{"href":251},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-listviews-part-2_6274-image_2.png",[23,253],{"style":254,"src":255,"border":27,"alt":28,"title":28,"width":256,"height":257},"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;","\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-listviews-part-2_6274-image_thumb.png",154,244,{"title":83,"searchDepth":84,"depth":84,"links":259},[],"2016-02-01T00:32:33.2900000-05:00",{},"\u002Farticles\u002Fxamarin-android-listviews-part-2-of-2",{"title":209,"description":214},"articles\u002Fxamarin-android-listviews-part-2-of-2",[95],"GDfb7Zf3hkjwtI7FU52rUJ_1EeuzVTcDs_ng1XAI9yo",1781574771150]