简体   繁体   中英

Android tabs, how to show image for selected tab

the current code shows colors the selected tab. I would like to change it to now show an image instead. the commented out code is what I thought would work and not sure why it does not. what should it be ????

Many thanks.

    public void onTabChanged(String tabId) {
        // TODO Auto-generated method stub
        for(int i=0;i<mTabHost.getTabWidget().getChildCount();i++)
  {
  TabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#404040"));


//what I thought would work is this below ?????
//mTabHost.getTabWidget().getChildAt(i).getResources().getDrawable(R.drawable.tabimg);


  } 

        mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#271B1B"));

    }

what have I missed. Thx Again.

Got it. Found my mistake ....silly of me. I should have used setBackgroundResource.

mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tabimg);

works now. thx.

Hope this helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM