![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
怎么设置tabhost的背景颜色
2个回答
2014-10-26 · 知道合伙人软件行家
关注
![](https://wyw-base.cdn.bcebos.com/pc-content/follow.gif)
展开全部
TabWidget tabWidget = tabHost.getTabWidget(); //获取TabHost的头部
for (int i=0; i<tabWidget.getChildCount(); i++){ //循环每个tabView
View view = tabWidget.getChildAt(i); //获取tabView项
view.setContentDescription(Integer.toString(i+1));
view.getLayoutParams().height = (int) (view.getLayoutParams().height / 1.2);
switch (i) {
case 0:{
view.setBackgroundResource(R.drawable.menu_1_selector);
break;
}
case 1:{
view.setBackgroundResource(R.drawable.menu_2_selector);
break;
}
case 2:{
view.setBackgroundResource(R.drawable.menu_3_selector);
break;
}
case 3:{
view.setBackgroundResource(R.drawable.menu_4_selector);
break;
}
}
}
}
![](https://ecmb.bdimg.com/tam-ogel/c8341ed9603766f55af354b205ebaf5e_60_60.jpg)
2020-07-03 广告
一般来说,电脑配色流程包括以下步骤:第一步:建立色彩数据库第二步:录入目标色第三步:计算配方第四步:修正配方以上每个步骤推荐使用彩谱配色软件ColorMatch V2.0+CS-820N。点击这里(杭州彩谱配色软件)可以直达了解详情。...
点击进入详情页
本回答由杭州彩谱科技有限公司提供
展开全部
package com.tony.tabstudy;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
public class TabStudyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec spec = tabHost.newTabSpec("tab1");
spec.setContent(R.id.tab1);
spec.setIndicator("主页");
tabHost.addTab(spec);
TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2");
spec2.setContent(R.id.tab2);
spec2.setIndicator("主页2", getResources().getDrawable(android.R.drawable.btn_dialog));
tabHost.addTab(spec2);
tabHost.setCurrentTab(1);
//初始化设置一次标签背景
updateTabBackground(tabHost);
//选择时背景更改。
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
updateTabBackground(tabHost);
}
});
}
/**
* 更新Tab标签的背景图
* @param tabHost
*/
private void updateTabBackground(final TabHost tabHost) {
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
View vvv = tabHost.getTabWidget().getChildAt(i);
if (tabHost.getCurrentTab() == i) {
//选中后的背景
vvv.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.spinner_background));
} else {
//非选择的背景
vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.a));
}
}
}
}
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
public class TabStudyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec spec = tabHost.newTabSpec("tab1");
spec.setContent(R.id.tab1);
spec.setIndicator("主页");
tabHost.addTab(spec);
TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2");
spec2.setContent(R.id.tab2);
spec2.setIndicator("主页2", getResources().getDrawable(android.R.drawable.btn_dialog));
tabHost.addTab(spec2);
tabHost.setCurrentTab(1);
//初始化设置一次标签背景
updateTabBackground(tabHost);
//选择时背景更改。
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
updateTabBackground(tabHost);
}
});
}
/**
* 更新Tab标签的背景图
* @param tabHost
*/
private void updateTabBackground(final TabHost tabHost) {
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
View vvv = tabHost.getTabWidget().getChildAt(i);
if (tabHost.getCurrentTab() == i) {
//选中后的背景
vvv.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.spinner_background));
} else {
//非选择的背景
vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.a));
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询