Android的tabhost改变文字颜色样式样式、颜色、文字、Android

由网友(Distance▎失落心)分享简介:试图改变tabhost文字的颜色,在这codeI可以改变tabhost backgound颜色(不是文本颜色)Trying to change tabhost text color , in this code i can change tabhost backgound color(not text color)...

试图改变tabhost文字的颜色,在这codeI可以改变tabhost backgound颜色(不是文本颜色)

Trying to change tabhost text color , in this code i can change tabhost backgound color(not text color)

  tabHost.setOnTabChangedListener(new OnTabChangeListener() {

            @Override
            public void onTabChanged(String tabId) {

                for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
                    tabHost.getTabWidget().getChildAt(i)
                            .setBackgroundColor(Color.parseColor("#FF0000")); // unselected
                }
                tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab())
                        .setBackgroundColor(Color.parseColor("#0000FF")); // selected

            }
        });

我怎么可以改变tabhost文字颜色?

how i can change tabhost text color ?

推荐答案

您可以更改Tabhost文本的颜色如下。

You may change color of Tabhost text as follow.

tabHost.setOnTabChangedListener(new OnTabChangeListener() {

    @Override
    public void onTabChanged(String tabId) {

        for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
            tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FF0000")); // unselected
            TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
            tv.setTextColor(Color.parseColor("#ffffff"));
        }

        tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#0000FF")); // selected
        TextView tv = (TextView) tabhost.getCurrentTabView().findViewById(android.R.id.title); //for Selected Tab
        tv.setTextColor(Color.parseColor("#000000"))

    }
});

编辑:

要初步确定文本颜色在您的活动,您可以使用 onResume这code()功能

To set text color initially in your activity, you can use this code in onResume() function

TabHost tabhost = getTabHost();
    for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) 
    {
        TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
        tv.setTextColor(Color.parseColor("#000000"));
    } 
阅读全文

相关推荐

最新文章