如何修复Tabhost for All活动

时间:2015-10-07 11:03:40

标签: android android-tabhost

如何修复Tabhost for All活动

这是我的反应。 我想在每一项活动中都这样做。 我有9个活动 我希望每个活动都有标签 给我最好的解决方案。如何在所有活动中加入标签? 这是我的反应。

package com.example.butter_event;

import java.util.ArrayList;





import android.R.color;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

public class Home_Page extends TabActivity {

    TabHost tabHost;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_page);

        tabHost = (TabHost) findViewById(android.R.id.tabhost);
        Intent intent=new Intent().setClass(this,Event_Home_Page.class);
        tabHost.setOnTabChangedListener(new OnTabChangeListener() {

            @Override
            public void onTabChanged(String tabId) {

                for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
                    tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#80FFFFFF")); // unselected
                    //TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
                    //tv.setTextColor(Color.parseColor("#460c00"));
                }

                tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#460c00")); // selected
                //TextView tv = (TextView) tabHost.getCurrentTabView().findViewById(android.R.id.title); //for Selected Tab
                //.setTextColor(Color.parseColor("#ffffff"));

            }
        });

        final TabSpec tab1 = tabHost.newTabSpec("First Tab");
        final TabSpec tab2 = tabHost.newTabSpec("Second Tab");
        final TabSpec tab3 = tabHost.newTabSpec("Third tab");
        final TabSpec tab4 = tabHost.newTabSpec("Fourth tab");
        final TabSpec tab5 = tabHost.newTabSpec("Five tab");

        // Set the Tab name and Activity
        // that will be opened when particular Tab will be selected
        tab1.setIndicator("");
        tab1.setIndicator(null,getResources().getDrawable(R.drawable.home_icon));
        tab1.setContent(new Intent(this, Event_Home_Page.class));

        tab2.setIndicator("");
        tab2.setIndicator(null,getResources().getDrawable(R.drawable.events_icon));
        tab2.setContent(new Intent(this, Events_Page.class));

        tab3.setIndicator("");
        tab3.setIndicator(null,getResources().getDrawable(R.drawable.maps_icon));
        tab3.setContent(new Intent(this, Vanue_List.class));

        tab4.setIndicator("");
        tab4.setIndicator(null,getResources().getDrawable(R.drawable.butter_me_icon));
        tab4.setContent(new Intent(this, Butter_Me.class));

        tab5.setIndicator("");
        tab5.setIndicator(null,getResources().getDrawable(R.drawable.gallary_icon));
        tab5.setContent(new Intent(this, Gallary_Page.class));



        /** Add the tabs to the TabHost to display. */
        tabHost.addTab(tab1);
        tabHost.addTab(tab2);
        tabHost.addTab(tab3);
        tabHost.addTab(tab4);
        tabHost.addTab(tab5);




    }





}

0 个答案:

没有答案