Android Studio - TabWiget implement assembly (FIG tape tab)

The final effect is shown below :( pick a little ugly emmm)

The main experiment involves:
1. Set the label text and pictures can not be displayed simultaneously issue
Solution: Modify AndroidManifest.xml in the android: theme becomes android: theme = " @android: style / Theme.Black "
in addition, the internet has said that you can customize View, temporarily did not try
2. Because white label text not clear, so the thought of changing the color of the word, a reference https://www.cnblogs.com /yuxuan007/p/7238980.html
final MainActivity.java code is as follows:

private TabHost tabhost;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tabhost = getTabHost();
    tv=(TextView)findViewById(R.id.sj);
    //View tabIndicator = LayoutInflater.from(this).inflate(R.layout.activity_receive_top, getTabWidget(), false);
    //增加选项卡名
    Intent ReceiveIntent = new Intent(MainActivity.this,ReceiveActivity.class);
    tabhost.addTab(tabhost.newTabSpec("tag1").setIndicator("收件箱",getResources().getDrawable(R.drawable.ic_tab_receive)).setContent(ReceiveIntent));
    Intent SendIntent = new Intent(MainActivity.this,SendActivity.class);
    tabhost.addTab(tabhost.newTabSpec("tag2").setIndicator("发件箱",getResources().getDrawable(R.drawable.ic_tab_send)).setContent(SendIntent));
    Intent DeletedIntent = new Intent(MainActivity.this,DeletedActivity.class);
    tabhost.addTab(tabhost.newTabSpec("tag3").setIndicator("已删除",getResources().getDrawable(R.drawable.ic_tab_deleted)).setContent(DeletedIntent));
    tabhost.setCurrentTabByTag("tag1");
    //选项卡切换事件处理
    tabhost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            upDateTab(tabhost);
            Toast.makeText(MainActivity.this,"当前选中:"+tabId+"标签",Toast.LENGTH_SHORT).show();
        }
    });
}
/**
 * 更新文字颜色。
 *
 * @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.colorAccent));
        } else {//不选中
            tv.setTextColor(this.getResources().getColor(R.color.colorPrimary));
        }
    }
}

Well, the end!

Guess you like

Origin www.cnblogs.com/pjshhh/p/12578938.html