Adding a display image to ActionBar.Tab

I am developing an Android application. I need to use Scroll through tabbed views . I want to add a drawn image ( non_click image ), when the tabs are loading and click the tab, another image of the same tab ( click_state image ) will appear. Please find below code I used.please help me do this

package com.example.creatingswipeviewswithtabs; import android.os.Bundle; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.ActionBar.TabListener; import android.app.Activity; import android.app.FragmentTransaction; import android.view.Menu; public class MainActivity extends Activity implements TabListener { ActionBar action_bar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); action_bar=getActionBar(); //action_bar.setBackgroundDrawable(d) action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab tab1=action_bar.newTab(); tab1.setText("Login"); tab1.setTabListener(this); ActionBar.Tab tab2=action_bar.newTab(); tab2.setText("Compare Now"); tab2.setTabListener(this); ActionBar.Tab tab3=action_bar.newTab(); tab3.setText("Search"); tab3.setTabListener(this); action_bar.addTab(tab1); action_bar.addTab(tab2); action_bar.addTab(tab3); } @Override public void onTabReselected(Tab arg0, FragmentTransaction arg1) { // TODO Auto-generated method stub } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } } 
+6
source share
1 answer

tabs is an array for Tab String s

 for (String tab_name : tabs) { actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this).setIcon(R.drawable.ic_launcher)); } 
+4
source

All Articles