I am using a Tabbed Page combined with a Master Detail Page for navigation in my Xamarin.Forms app. Currently when a menu option is selected from the Master Detail Page a new tabbed page is added with the page's content. I want to place a button to close the tab in the title field of the tab. Is this possible? Currently I just have a button within the content page for the tab, but this is less than ideal. I want it to be very web browser like. Thanks in advance!
Edit: I have added the image. Basically, I just want to add an "X" button to the right of each item in the tab bar that would allow me to close that tab. Just like you would in Chrome or something.
You can use custom renderer to create your custom
TabbedPage
in android platform. Disagree with Yuri, on android we can add an image to tab, in fact we can customize the layout of tab.Since in your image, I saw you didn't use the
Icon
property for each tab, I use this icon as a close button. But sure you can also not use this, it is self customized.In PCL, create a
MyTabbedPage
:In Android platform create a renderer for it:
Use it like this:
Code behind, don't forget to change
MainPage
to inherit fromMyTabbedPage
:Please pay attention here, if you look closer to my code, you will find that I used
Title
of each tab for the comparing and removing the matching item, it will find the first matched title and remove the page of that title. This may cause a problem if you have several tabs with the same title. This is a potential bug of this demo, you may try to solve it.Update:
Forgot to post the code of
mytablayout
, here is it: