當前位置: 首頁>>代碼示例>>Java>>正文


Java FragmentTabHost.setOnTabChangedListener方法代碼示例

本文整理匯總了Java中android.support.v4.app.FragmentTabHost.setOnTabChangedListener方法的典型用法代碼示例。如果您正苦於以下問題:Java FragmentTabHost.setOnTabChangedListener方法的具體用法?Java FragmentTabHost.setOnTabChangedListener怎麽用?Java FragmentTabHost.setOnTabChangedListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.app.FragmentTabHost的用法示例。


在下文中一共展示了FragmentTabHost.setOnTabChangedListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
    mTabHost.getTabWidget().setBackgroundColor(getResources().getColor(R.color.tab_bg));
    mTabHost.getTabWidget().setDividerDrawable(null);
    mTabHost.setOnTabChangedListener(this);

    TabInfo[] tabs = createTabInfo();
    if (tabs != null) {

        for (TabInfo tabInfo : tabs) {
            mTabHost.addTab(mTabHost.newTabSpec(tabInfo.tag).setIndicator(getTabItemView(tabInfo.bitmapResId, getString(tabInfo.titleSId))),
                    tabInfo.fragment, null);
        }
    }

    mTabHost.getTabWidget().getChildAt(0).getLayoutParams().height = (int) getResources().getDimension(R.dimen.tab_height);

}
 
開發者ID:beanu,項目名稱:smart-farmer-android,代碼行數:24,代碼來源:NavBarActivity.java

示例2: init

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
public void init(FragmentTabHost fragmentTabHost, Activity activity) {
	this.activity = activity;
       // 得到fragment的個數
       int count = classArray.length;

       for (int i = 0; i < count; i++) {
           // 給每個Tab按鈕設置圖標、文字和內容
           TabSpec tabSpec = fragmentTabHost.newTabSpec(labelArray[i]).setIndicator(
                   getTabItemView(i, activity));
           // 將Tab按鈕添加進Tab選項卡中
           fragmentTabHost.addTab(tabSpec, classArray[i], null);

           // 設置Tab按鈕的背景
           //mTabHost.getTabWidget().getChildAt(i)
           // .setBackgroundResource(R.drawable.tt_tab_bk);
       }
	this.selectTab(0);
	fragmentTabHost.setOnTabChangedListener(this);
}
 
開發者ID:xuhuisheng,項目名稱:lemon-android,代碼行數:20,代碼來源:FragmentHelper.java

示例3: initView

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
private void initView() {
    mAddItem = (LinearLayout) findViewById(R.id.main_add_item);
    mTabHost = (FragmentTabHost) findViewById(R.id.main_tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.main_container);
    mTabHost.setBackgroundColor(getResources().getColor(R.color.bg_tabhost));
    mTabHost.getTabWidget().setDividerDrawable(null);
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (tabId.equals(BlackListFragmet.NAME)) {
                mActionBar.setTitle("黑名單", LocalActionBar.MIDDLE_TITLE);
        //        mAddItem.setVisibility(View.VISIBLE);
            } else {
                mActionBar.setTitle("添加", LocalActionBar.MIDDLE_TITLE);
        //        mAddItem.setVisibility(View.GONE);
            }
        }
    });
    addTabItem(BlackListFragmet.NAME, "黑名單", BlackListFragmet.TAB_ICON, BlackListFragmet.class);
    addTabItem(AddDataFragment.NAME, "添加", AddDataFragment.TAB_ICON, AddDataFragment.class);
}
 
開發者ID:facetome,項目名稱:Interceptor,代碼行數:22,代碼來源:MainActivity.java

示例4: initView

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
private void initView() {
    //測試欄目的題目統計TextView
    mCount = (TextView) findViewById(R.id.tv_count);
    mDoubleClickExit = new DoubleClickExitHelper(this);

    Indicator[] indicators = Indicator.values();
    mFragmentTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mFragmentTabHost.setup(getApplicationContext(), getSupportFragmentManager(), R.id.realtabcontent);

    //初始化Tab
    for (int i = 0; i < indicators.length; i++){
        TabHost.TabSpec tabSpec = mFragmentTabHost.newTabSpec(getString(indicators[i].getResName()));
        tabSpec.setIndicator(getIndicatorView(indicators[i]));
        mFragmentTabHost.addTab(tabSpec, indicators[i].getClz(), null);
    }
    //去除底部按鈕之間的分割線
    if (android.os.Build.VERSION.SDK_INT > 10) {
        mFragmentTabHost.getTabWidget().setShowDividers(0);

        mFragmentTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
            @Override
            public void onTabChanged(String tabId) {
                if(tabId.equals(getString(Indicator.TEST.getResName()))){
                    mCount.setVisibility(View.VISIBLE);
                }else{
                    mCount.setVisibility(View.GONE);
                }
            }
        });
}}
 
開發者ID:FallenCrood,項目名稱:Review-,代碼行數:31,代碼來源:MainActivity.java

示例5: initTabHost

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
private void initTabHost() {
    //實例化FragmentTabHost對象
    FragmentTabHost fragmentTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    fragmentTabHost.setup(this,getSupportFragmentManager(),android.R.id.tabcontent);

    //去掉分割線
    fragmentTabHost.getTabWidget().setDividerDrawable(null);

    for (int i = 0; i<mTableItemList.size(); i++) {
        TabItem tabItem = mTableItemList.get(i);
        //實例化一個TabSpec,設置tab的名稱和視圖
        TabHost.TabSpec tabSpec = fragmentTabHost.newTabSpec(tabItem.getTitleString()).setIndicator(tabItem.getView());
        fragmentTabHost.addTab(tabSpec,tabItem.getFragmentClass(),null);

        //給Tab按鈕設置背景
        fragmentTabHost.getTabWidget().getChildAt(i).setBackgroundColor(getResources().getColor(R.color.main_bottom_bg));

        //默認選中第一個tab
        if(i == 0) {
            tabItem.setChecked(true);
        }
    }

    fragmentTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            //重置Tab樣式
            for (int i = 0; i< mTableItemList.size(); i++) {
                TabItem tabitem = mTableItemList.get(i);
                if (tabId.equals(tabitem.getTitleString())) {
                    tabitem.setChecked(true);
                }else {
                    tabitem.setChecked(false);
                }
            }
        }
    });
}
 
開發者ID:zhangbz,項目名稱:FragmentTabHost,代碼行數:39,代碼來源:MainActivity.java

示例6: onCreateView

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_tab_host_fragment, container, false);

    // TabHostの初期化
    FragmentTabHost host = (FragmentTabHost) rootView.findViewById(R.id.tabHost);
    host.setup(getActivity(), getFragmentManager(), android.R.id.tabcontent);

    // ListViewFragmentのTabを追加
    TabHost.TabSpec tabSpec1 = host.newTabSpec("List").setIndicator("List");
    host.addTab(tabSpec1, ListViewFragment.class, null);

    // GridViewFragmentのTabを追加
    TabHost.TabSpec tabSpec2 = host.newTabSpec("Grid").setIndicator("Grid");
    host.addTab(tabSpec2, GridViewFragment.class, null);

    // ScrollViewFragmentのTabを追加
    TabHost.TabSpec tabSpec3 = host.newTabSpec("Scroll").setIndicator("Scroll");
    host.addTab(tabSpec3, ScrollViewFragment.class, null);

    // リスナーをセット
    host.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            //切り替えたTabのIDを表示
            Toast.makeText(getActivity(), "selected " + tabId, Toast.LENGTH_SHORT).show();
        }
    });

    return rootView;
}
 
開發者ID:yokmama,項目名稱:honki_android2,代碼行數:33,代碼來源:FragmentTabHostFragment.java

示例7: initView

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
/**
 * init views in MainActivity
 */
private void initView() {
    mFragmentTabHost = (FragmentTabHost) findViewById(R.id.tab_host);
    mFragmentTabHost.setup(this, getSupportFragmentManager(), R.id.frame_container);

    mMainTab = getIndicator(MainActivity.this, mFragmentTabHost.newTabSpec(TAB_MAIN_TAG), "#363636",
            "Solution", R.mipmap.problem);
    mWebTab = getIndicator(MainActivity.this, mFragmentTabHost.newTabSpec(TAB_WEB_TAG), "#363636",
            "Discussion", R.mipmap.discussion);

    mFragmentTabHost.addTab(mMainTab, MainListContainerFragment.class, null);
    mFragmentTabHost.addTab(mWebTab, WebContainerFragment.class, null);
    mFragmentTabHost.getTabWidget().setDividerDrawable(null); // Remove the divider
    mFragmentTabHost.getCurrentTabView().setBackgroundColor(Color.parseColor("#1E1E1E"));
    mFragmentTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            switch (tabId) {
                case "main":
                    mFragmentTabHost.getTabWidget().getChildTabViewAt(0)
                            .setBackgroundColor(Color.parseColor("#1E1E1E"));
                    mFragmentTabHost.getTabWidget().getChildTabViewAt(1)
                            .setBackgroundColor(Color.parseColor("#363636"));
                    break;
                case "web":
                    mFragmentTabHost.getTabWidget().getChildTabViewAt(1)
                            .setBackgroundColor(Color.parseColor("#1E1E1E"));
                    mFragmentTabHost.getTabWidget().getChildTabViewAt(0)
                            .setBackgroundColor(Color.parseColor("#363636"));
                    break;
            }
        }
    });
}
 
開發者ID:zhouyizirui,項目名稱:Leetroid,代碼行數:37,代碼來源:MainActivity.java

示例8: onCreate

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_file_selector);

    serverResponse = getIntent().getStringExtra("serverResponse");
    previousSelectedFile = FileSelectHelper.getFileEntityByFileId(FileSelectHelper.getFileEntities(serverResponse), getIntent().getStringExtra("fileId"));

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        toolbar.setTitleTextColor(getResources().getColor(R.color.fs_colorAccent));
        getSupportActionBar().setDisplayShowTitleEnabled(false);
    }

    // Init main tab host categories {My files and Sample files} that is placed in bottom
    tabHostCategory = (FragmentTabHost) findViewById(R.id.tabCategory);
    tabHostCategory.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);

    myFilesTabContent = getTabIndicator(tabHostCategory, "My files", R.drawable.my_files_icon_sequencing_com_gray);
    sampleFilesTabContent = getTabIndicator(tabHostCategory, "Sample files", R.drawable.sample_files_icon_sequencing_com_gray);

    tabHostCategory.addTab(tabHostCategory.newTabSpec(FileSelectHelper.ATTR_MY_FILES).setIndicator(myFilesTabContent), MyFileActivity.class, null);
    tabHostCategory.addTab(tabHostCategory.newTabSpec(FileSelectHelper.ATTR_SAMPLE).setIndicator(sampleFilesTabContent), SampleFileActivity.class, null);
    changeTabContent(myFilesTabContent, R.color.fs_colorAccent, R.drawable.my_files_icon_sequencing_com_color);

    tabHostCategory.setOnTabChangedListener(this);

    if(FileSelectHelper.isEmptyMyFiles(serverResponse)) {
        tabHostCategory.getTabWidget().getChildTabViewAt(1).performClick();
        tabHostCategory.getTabWidget().getChildTabViewAt(0).setEnabled(false);
    }

    if(getIntent().getStringExtra("tab").equals("sample_files")) {
        tabHostCategory.getTabWidget().getChildTabViewAt(1).performClick();
    }
}
 
開發者ID:SequencingDOTcom,項目名稱:RTP-API-Gradle-Maven-Android-File-Selector-Java,代碼行數:38,代碼來源:FileSelectorActivity.java

示例9: init

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void init(Bundle savedInstanceState) {
    super.init(savedInstanceState);
    mPagerWrapper = (LinearLayout) findViewById(R.id.pager_wrapper);
    mTagHeight = 0;
    mPagerWrapper.setPadding(0, getActionBarSize() + mTagHeight, 0, 0);
    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
    mTabHost.getTabWidget().setShowDividers(0);
    initTabs();
    mTabHost.setCurrentTab(0);
    mTabHost.setOnTabChangedListener(this);

}
 
開發者ID:godblessyouandme,項目名稱:appFirst,代碼行數:16,代碼來源:MainActivity.java

示例10: onCreateView

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_tab_host, container, false);

    //TabHostの初期化
    FragmentTabHost host = (FragmentTabHost) rootView.findViewById(R.id.tabHost);
    host.setup(getActivity(), getFragmentManager(), android.R.id.tabcontent);

    //ListViewFragmentのTabを追加
    TabHost.TabSpec tabSpec1 = host.newTabSpec("List").setIndicator("List");
    host.addTab(tabSpec1, ListViewFragment.class, null);

    //GridViewFragmentのTabを追加
    TabHost.TabSpec tabSpec2 = host.newTabSpec("Grid").setIndicator("Grid");
    host.addTab(tabSpec2, GridViewFragment.class, null);

    //ScrollViewFragmentのTabを追加
    TabHost.TabSpec tabSpec3 = host.newTabSpec("Scroll").setIndicator("Scroll");
    host.addTab(tabSpec3, ScrollViewFragment.class, null);

    //リスナーをセット
    host.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            //切り替えたTabのIDを表示
            Toast.makeText(getActivity(), "selected " + tabId, Toast.LENGTH_SHORT).show();
        }
    });

    return rootView;
}
 
開發者ID:yokmama,項目名稱:honki_android,代碼行數:33,代碼來源:TabHostFragment.java

示例11: init

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
@Override
protected void init(Bundle savedInstanceState) {
    super.init(savedInstanceState);

    mToolbarView = findViewById(R.id.actionBar);

    final int tabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);
    findViewById(R.id.pager_wrapper).setPadding(0, getActionBarSize() + tabHeight, 0, 0);

    mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
    if (Build.VERSION.SDK_INT > 10) {
        mTabHost.getTabWidget().setShowDividers(0);
    }

    initTabs();

    mTabHost.setCurrentTab(0);
    mTabHost.setOnTabChangedListener(this);

    ViewConfiguration vc = ViewConfiguration.get(this);
    mSlop = vc.getScaledTouchSlop();
    mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.container);
    mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);
}
 
開發者ID:leerduo,項目名稱:OschinaMainFrameWorkWithToolBar,代碼行數:28,代碼來源:MainActivity.java

示例12: init

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void init(Bundle savedInstanceState) {
    super.init(savedInstanceState);
    checkUpdate();

    AppContext.instance().initLoginInfo();

    mToolbarView = findViewById(R.id.actionBar);

    final int tabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);
    findViewById(R.id.pager_wrapper).setPadding(0, getActionBarSize() + tabHeight, 0, 0);

    mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
    if (Build.VERSION.SDK_INT > 10) {
        mTabHost.getTabWidget().setShowDividers(0);
    }

    initTabs();

    mTabHost.setCurrentTab(0);
    mTabHost.setOnTabChangedListener(this);

    IntentFilter filter = new IntentFilter(Constants.INTENT_ACTION_NOTICE);
    registerReceiver(mNoticeReceiver, filter);

    NoticeUtils.bindToService(this);
    UIHelper.sendBroadcastForNotice(this);

    ViewConfiguration vc = ViewConfiguration.get(this);
    mSlop = vc.getScaledTouchSlop();
    mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.container);
    mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);
}
 
開發者ID:blueelwang,項目名稱:oschina-app,代碼行數:38,代碼來源:MainActivity.java

示例13: initTabs

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
@SuppressLint("NewApi")
private void initTabs() {
    tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    tabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
    tabHost.setOnTabChangedListener(this);
    tabs = (TabWidget) findViewById(android.R.id.tabs);
    // tabs.setShowDividers(TabWidget.SHOW_DIVIDER_NONE);

    addTab(R.drawable.tab_icon_typography, TypographyContainer.class);
    addTab(R.drawable.tab_icon_listview, ListViewContainer.class);
    addTab(R.drawable.tab_icon_gridview, GridViewContainer.class);
    addTab(R.drawable.tab_icon_buttons, ButtonsContainer.class);
    addTab(R.drawable.tab_icon_icons, IconsContainer.class);
}
 
開發者ID:Pixate,項目名稱:pixate-freestyle-android,代碼行數:15,代碼來源:MainFrameActivity.java

示例14: initViews

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
private void initViews(final View view) {

        mOwnerImageView = (RoundedCornerImageView) view.findViewById(R.id.image_user);
        mChatImageView = (ImageView) view.findViewById(R.id.chat_with_owner);

        mChatImageView.setOnClickListener(this);
        mOwnerNameTextView = (TextView) view.findViewById(R.id.text_user_name);
        mOwnerBarterLocationTextView = (TextView) view
                .findViewById(R.id.text_user_location);
        mDragHandle = view.findViewById(R.id.container_profile_info);

        mTabHost = (FragmentTabHost) view.findViewById(android.R.id.tabhost);
        mTabHost.setup(getActivity(), getChildFragmentManager(), android.R.id.tabcontent);
        mTabHost.addTab(mTabHost.newTabSpec(FragmentTags.ABOUT_ME)
                        .setIndicator(getString(R.string.about_me)), DummyFragment.class,
                null
        );
        mTabHost.addTab(mTabHost.newTabSpec(FragmentTags.MY_BOOKS)
                        .setIndicator(getString(R.string.my_books)), DummyFragment.class,
                null
        );
        mTabHost.setOnTabChangedListener(this);

        mViewPager = (ViewPager) view.findViewById(R.id.pager_profile);
        mProfileFragmentsAdapter = new ProfileFragmentsAdapter(getChildFragmentManager());
        mViewPager.setAdapter(mProfileFragmentsAdapter);
        mViewPager.setOnPageChangeListener(this);

    }
 
開發者ID:barterli,項目名稱:barterli_android,代碼行數:30,代碼來源:ProfileFragment.java

示例15: init

import android.support.v4.app.FragmentTabHost; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
protected void init(Bundle savedInstanceState) {
	super.init(savedInstanceState);

	// Intent intent = getIntent();
	// if (intent != null) {
	// mVersion = intent.getParcelableExtra(Version.BUNDLE_KEY_VERSION);
	// }

	AppContext.instance().initLoginInfo();

	mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
	mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
	if (android.os.Build.VERSION.SDK_INT > 10) {
		mTabHost.getTabWidget().setShowDividers(0);
	}

	initTabs();

	mTabHost.setCurrentTab(0);
	mTabHost.setOnTabChangedListener(this);
	
	IntentFilter filter = new IntentFilter(Constants.INTENT_ACTION_NOTICE);
	registerReceiver(mNoticeReceiver, filter);

	NoticeUtils.bindToService(this);
	UIHelper.sendBroadcastForNotice(this);
}
 
開發者ID:447491480,項目名稱:ima_intellj,代碼行數:30,代碼來源:MainActivity.java


注:本文中的android.support.v4.app.FragmentTabHost.setOnTabChangedListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。