1

I want to set text in action bar tab dynamically. Showing that the feature is not available. How to do that? i had changed the disable tab icon dynamically as you can see in the image in the link

audioTab = actionBar.newTab();
actionBar.setIcon(mSectionsPagerAdapter.getIcon(i));
actionBar.setText(mSectionsPagerAdapter.getPageTitle(i));
actionBar.setTabListener(this);
actionBar.addTab(audioTab);
//changing icon dynamically
audioTab.setIcon(R.drawable.audio_disabled);
videoTab.setIcon(R.drawable.video_disabled);

2 Answers2

1

I did a little research, and because you are not using TabHost (which can access each seperate view), you should set each Tab a custom view, via setCustomView(), and when you want to change it

  • get the tab via actionBar.getTabAt()
  • tab has methods like getCustomView() where you can find your custom text view (via findViewById) and than just apply strike through text like this answer demonstrates

TextView textView = (TextView) findViewById(R.id.some_text_view); textView.setText(someString); textView.setPaintFlags(textView .getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

Or you can apply a different custom view, instead of changing the existing text view.

Let me know if you need any further help or explanation.

Community
  • 1
  • 1
Marko
  • 20,385
  • 13
  • 48
  • 64
0

A few answers for changing the title/icon of the ActionBar here.

As for 'strikethrough' text, you would likely need to override the ActionBar class so that it intercepts text changes, and draws a line through the text based on it's width... not that I can think of a single reason why you would want to have a strkethrough effect on what is essentially a page title. Here is some starting points on styling the ActionBar.

Here's a link I found by searching for "extend ActionBar" android in Google. This guy seems to be having a go of it.

There should be plenty of pointers if you're sharp enough to decipher the source code.

Community
  • 1
  • 1
1owk3y
  • 1,115
  • 1
  • 15
  • 30
  • did you check the image that i attached in question.I just want to show the user that this feature is not available in actionbar tab not actionbar – Shyam James Jul 14 '15 at 05:42