小编Gau*_*raw的帖子

如何更改选项卡指示器的颜色

我在我的应用程序中使用tabHost,并且要求是当选择任何选项卡时,选项卡指示器的颜色应该更改,我参考此示例如何在Android中设置选项卡视图指示器背景颜色但我不理解这是我的代码:

    TabHost tabHost = getTabHost();  // The activity TabHost

            TabHost.TabSpec spec;  // Reusable TabSpec for each tab
            Intent intent;  // Reusable Intent for each tab

            // Create an Intent to launch an Activity for the tab (to be reused)
            intent = new Intent().setClass(this, HomePage.class);
            // Initialize a TabSpec for each tab and add it to the TabHost
            spec = tabHost.newTabSpec("tabOne");  
            spec.setContent(intent);  
            spec.setIndicator("Home");  
            tabHost.addTab(spec);
            // Squash the tab a little bit horizontally
            tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 40;
            tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 50;

            // …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-tabhost android-tabs

2
推荐指数
1
解决办法
2万
查看次数