开发者

How to change the TabHost back ground color

I am doing android application using Tab Host. I want to change the background color instead of giving default color from android operating system. i google this issue i got some solution and i made coding.

 for (i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { 
        mTabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.LTGRAY); 
        } 
    mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#000000")); 

In this code the first tab getting change of color whenever i click the another(ie next tab) Tab the color will n开发者_JAVA技巧ot change. if anyone have idea of this particular issue, ple guide me.


you have to add a Listener to your tabHost, sth. like

mtabHost.setOnTabChangedListener(new OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            setTabColor(mtabHost);
        }
});

where setTabColor() contains your code.


TabWidget tw = tabHost.getTabWidget(); tw.setBackgroundDrawable(getResources().getDrawable(R.drawable.xxxxxx));

//and you have to override
public void onTabChanged(String tabId) {
Activity activity = getLocalActivityManager().getActivity(tabId);
if (activity != null) {
activity.onWindowFocusChanged(true);
}
}


Because of states and selectors, this is more complicated than you might think. I've found the following website useful when customizing tabs before: http://joshclemm.com/blog/?p=136

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜