How to set image in tabhost in android? -


i building android application using 4 tablayout.

now wanna set image in place of text in handing of tablayout.

i using code of link - http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/

here code -

mainactivity.java package info.androidhive.tabsswipe;       public class mainactivity extends fragmentactivity implements     actionbar.tablistener {      private viewpager viewpager;     private tabspageradapter madapter;     private actionbar actionbar;     // tab titles    private string[] tabs = { "top rated", "games", "movies" };  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      // initilization     viewpager = (viewpager) findviewbyid(r.id.pager);     actionbar = getactionbar();     madapter = new tabspageradapter(getsupportfragmentmanager());      viewpager.setadapter(madapter);     actionbar.sethomebuttonenabled(false);     actionbar.setnavigationmode(actionbar.navigation_mode_tabs);              // adding tabs     (string tab_name : tabs) {         actionbar.addtab(actionbar.newtab().settext(tab_name)                 .settablistener(this));     }      /**      * on swiping viewpager make respective tab selected      * */     viewpager.setonpagechangelistener(new viewpager.onpagechangelistener() {          @override         public void onpageselected(int position) {             // on changing page             // make respected tab selected             actionbar.setselectednavigationitem(position);         }          @override         public void onpagescrolled(int arg0, float arg1, int arg2) {         }          @override         public void onpagescrollstatechanged(int arg0) {         }     }); }  @override public void ontabreselected(tab tab, fragmenttransaction ft) { }  @override public void ontabselected(tab tab, fragmenttransaction ft) {     // on tab selected     // show respected fragment view     viewpager.setcurrentitem(tab.getposition()); }  @override public void ontabunselected(tab tab, fragmenttransaction ft) { }  } 

here fragment code -

package info.androidhive.tabsswipe;  public class moviesfragment extends fragment {  @override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {      view rootview = inflater.inflate(r.layout.fragment_movies, container, false);      return rootview; }  } 

change this:

for (string tab_name : tabs) {     actionbar.addtab(actionbar.newtab().settext(tab_name)             .settablistener(this)); } 

to this:

for (string tab_name : tabs) {     actionbar.addtab(actionbar.newtab().settext("")             .settablistener(this).seticon(r.drawable.your_icon)); } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -