How to add a close button to action bar tabs -


I am creating an app and it has an action bar of up to four tabs. I have a web browser Like I would like to add a close button

I know how to add / delete the tabs dynamically I was looking at the way to add a close button, but I could not find anything!

If you know a solution or tutorial, please tell me or is it (adding a close button in the tab) is a bad practice?

Thanks,

My environment: Android 4.4.2 (API-level 19)

I found the solution I could solve my problem using ActionBar.Tab # setCustomView method. . This is an idea that you can add to create for the Action Bar tab

My code is:

  ActionBar ActionBar = getSupportActionBar (); actionBar.addTab (ActionBar .newTab () .setCustomView (R.layout.tab_title) .setTabListener (New MainTabListener & lt; TabFragment> (this, "myTab", TabFragment.class)));   

More information about adding tabs to action bar can be found here:

For example, my tab_title.xml is:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; RelativeLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" android: layout_height = "match_parent" & gt; & Lt; Android: layout_alignParentEnd = "true" Android: singleLine = "true" Android: paddingStart = "0dp" Android: PaddingLeft = Android: layout_alignParentStart = "true" Android: layout_alignParentTop = "true" Android: Ellipsize = "end" Android: gravity = "center" Android: singleLine = "true" "0dp" Android: paddingEnd = "10dp" Android: paddingRight = "10dp" /> & Lt; Android: layout_height = "wrap_content" android: layout_alignParentBottom = "true" android: layout_alignParentEnd = "true" android: layout_alignParentRight = "true" android: layout_alignParentTop: textView android: id = "@ + id / close_tab" Android: layout_width = "wrap_content" Android: layout_gravity = "fill_vertical" Android: layout_toLeftOf = "@ + id / title_tab" Android: layout_toStartOf = "@ + id / title_tab" Android: gravity = "center" Android: text = "x" Android: textSize = "10sp" Android: Text-style = "bold" Android: paddingStart = "10dp" Android: paddingLeft = "10dp" Android: paddingEnd = "0dp" A Droid: paddingRight = "0dp" / & gt; & Lt; / RelativeLayout & gt;   

Then, for the textView of the close button, click the listener, then you can create a close button in the Action Bar tab.

I hope this post helps someone.

WARNING: If you enable device rotation, please keep this issue in mind:

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -