Updating Android Tab Icons

前端 未结 5 1125
广开言路
广开言路 2020-12-08 04:26

I have an activity which has a TabHost containing a set of TabSpecs each with a listview containing the items to be displayed by the tab. When each TabSpec is created, I set

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 04:52

    Try This:

    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
        public void onTabChanged(String tabId) {
            if (TAB_MAP.equals(tabId)) {
                ImageView iv = (ImageView) tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.icon);
                iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_map_black));
                iv = (ImageView) tabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.icon);
                iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_list_white));
            } else if (TAB_LIST.equals(tabId)) {
                ImageView iv = (ImageView) tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.icon);
                iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_map_white));
                iv = (ImageView) tabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.icon);
                iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_list_black));
            }
        }
    });
    

提交回复
热议问题