Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding drawable image into ActionBar.Tab

Tags:

android

I'm developing Android Application.there i have to use Swipe Views with Tabs . i want to add drawable image(non_click image) when tabs load & press the tab there will be another image of same tab (click_state image) .Please find below the code I used.please help me to do it

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

    }




}
like image 771
VenushkaT Avatar asked Feb 01 '14 08:02

VenushkaT


1 Answers

tabs is an array for Tab Strings

for (String tab_name : tabs) {
     actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this).setIcon(R.drawable.ic_launcher));           
}
like image 200
ashish Avatar answered Sep 30 '22 16:09

ashish