for (int i = 0; i < tabWidget.getChildCount(); i++) { final TextView textView = (TextView) tabWidget.getChildAt(i).findViewById(R.id.tabtext); textView.setTextColor(Color.BLUE); } }
private void makeTab() { res = getResources(); tabHost = getTabHost();
你的资源,我下载不了,你能用email发给我吗?thanks
我的email: [email protected]
再问3楼和5楼:<?xml version="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_unselected" />
<item
android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/onselect" />
<item
android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/onselect" />
<item
android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/onselect" />
<item
android:state_pressed="true"
android:drawable="@drawable/onselect" />
</selector>1 这个xml是用来设置,选中某选项时,会跟上一背景图,对吗
2 现如果要在选中某选项时,还要再把选中项的文字的颜色变成红色,怎么实现呀
thanks
是在6楼提到的selector中写程序吗?还是?
private TabWidget tabWidget;
Resources res;
TabHost tabHost;
TabHost.TabSpec spec;
Intent intent;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
makeTab();
processTab();
}
tabWidget = (TabWidget) findViewById(android.R.id.tabs);
for (int i = 0; i < tabWidget.getChildCount(); i++) {
final TextView textView = (TextView) tabWidget.getChildAt(i).findViewById(R.id.tabtext);
textView.setTextColor(Color.BLUE);
}
}
res = getResources();
tabHost = getTabHost();
View tabView = View.inflate(this, R.layout.tab_view, null);
ImageView imageView = (ImageView) tabView.findViewById(R.id.tabimage);
imageView.setImageResource(R.drawable.e010);
TextView textView = (TextView) tabView.findViewById(R.id.tabtext);
textView.setText("我不懂");
intent = new Intent().setClass(this, TestCalendarActivity.class);
spec = tabHost.newTabSpec("first").setIndicator(tabView)
.setContent(intent);
tabHost.addTab(spec);
对啊,tabhost是一个布局 里面可以放这些:头条,都市。等等
但是这个头条按下的效果,非按下的效果可以在selector中实现至于头条对应的内容,就需要额外一个布局了 ,扯远了 。有点晕温馨提示:LZ可以结贴了
public void onTabChanged(String tabId) {
//tabId值为要切换到的tab页的索引位置
int tabID = Integer.valueOf(tabId);
for (int i = 0; i < tabWidget.getChildCount(); i++)
{
if (i == tabID)
{
tabWidget.getChildAt(Integer.valueOf(i));
final TextView textView = (TextView) tabWidget.getChildAt(Integer.valueOf(i)).findViewById(R.id.title);
textView.setTextColor(0xffFEFFFF);
}
else
{
tabWidget.getChildAt(Integer.valueOf(i));
final TextView textView = (TextView) tabWidget.getChildAt(Integer.valueOf(i)).findViewById(R.id.title);
textView.setTextColor(0xff767674);
}
}
}