tabhost改变标签颜色
Posted 张裕轩
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tabhost改变标签颜色相关的知识,希望对你有一定的参考价值。
package uiframe.zyx.uiframe.com.uiframe.fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;
import android.widget.TextView;
import uiframe.zyx.uiframe.com.uiframe.R;
import static uiframe.zyx.uiframe.com.uiframe.R.id.tab1;
/**
* Created by DELL on 2017-07-06.
*/
public class OneFragment extends Fragment{
private View view;
private TabHost mTabHost;
private TextView mTextView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_one,null);
// init();
mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
mTextView = (TextView) view.findViewById(android.R.id.title);
mTabHost.setup();
inflater.inflate(R.layout.ceshi,mTabHost.getTabContentView());
inflater.inflate(R.layout.ceshi,mTabHost.getTabContentView());
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("MAC采集").setContent(tab1));
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("黑名单").setContent(R.id.tab2));
/* mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
// upDateTab(mTabHost);
}
});*/
return view;
}
/**
* 更新文字颜色。
*
* @param mTabHost
*/
/*private void upDateTab(TabHost mTabHost) {
for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {
TextView tv = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
if (mTabHost.getCurrentTab() == i) {//选中
tv.setTextColor(this.getResources().getColor(R.color.sys_skin));
} else {//不选中
tv.setTextColor(this.getResources().getColor(R.color.sys_black));
}
}
}*/
}
以上是关于tabhost改变标签颜色的主要内容,如果未能解决你的问题,请参考以下文章
当我在eclipse中单击按钮时,使用tabHost并转到特定选项卡
android 开发,TabHost 做标签页 ,求大神指教