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


Java TabLayout.addOnTabSelectedListener方法代碼示例

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


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

示例1: onCreate

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);

    //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //setSupportActionBar(toolbar);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = findViewById(R.id.tabs);

    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
}
 
開發者ID:AndProx,項目名稱:AndProx,代碼行數:21,代碼來源:AboutActivity.java

示例2: getView

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Override
protected ViewGroup getView() {
    // RecyclerViewPresenter returns a RecyclerView. We inflate it in a bigger container.
    ViewGroup rv = super.getView();
    ViewGroup container = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.male_female_popup, null);
    // Add RecyclerView to our container
    ViewGroup rvContainer = (ViewGroup) container.findViewById(R.id.recycler_view_container);
    rvContainer.addView(rv, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    // Set up bar that reacts to clicks and syncs with 'females' boolean
    TabLayout tabLayout = (TabLayout) container.findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText("Males"));
    tabLayout.addTab(tabLayout.newTab().setText("Females"));
    tabLayout.getTabAt(females ? 1 : 0).select();
    tabLayout.addOnTabSelectedListener(this);
    return container;
}
 
開發者ID:natario1,項目名稱:Autocomplete,代碼行數:17,代碼來源:MaleFemalePresenter.java

示例3: onCreate

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
    initTabList();
    mAdapter = new TabLayoutFragmentAdapter(getSupportFragmentManager(), mTabList, this, mFragments, mTabImgs);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setCurrentItem(0);
    mTabLayout.setupWithViewPager(mViewPager);
    mTabLayout.setTabMode(TabLayout.MODE_FIXED);
    for (int i = 0; i < mTabLayout.getTabCount(); i++) {
        mTabLayout.getTabAt(i).setCustomView(mAdapter.getTabView(i));
    }
    mTabLayout.addOnTabSelectedListener(this);
}
 
開發者ID:auv1107,項目名稱:TextEmoji,代碼行數:21,代碼來源:MainActivity.java

示例4: onCreate

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_top_tabs);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Create the adapter that will return a fragment for each of the three
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));

    final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

}
 
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:31,代碼來源:TopTabsActivity.java

示例5: onCreateView

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  View view = inflater.inflate(R.layout.fragment_news, container, false);
  toolbar = (Toolbar) view.findViewById(R.id.toolbar);
  toolbar.setTitle(getString(R.string.title_news));

  tabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
  viewPager = (ViewPager) view.findViewById(R.id.viewPager);

  tabLayout.addOnTabSelectedListener(this);
  viewPager.addOnPageChangeListener(this);
  viewPager.setAdapter(new FragmentStatePagerAdapter(getFragmentManager()) {
    @Override
    public Fragment getItem(int position) {
      switch (position) {
        case 0:
          return itNewsFragment;
        case 1:
          return otherNewsFragment;
      }
      return null;
    }

    @Override
    public int getCount() {
      return 2;
    }
  });

  return view;
}
 
開發者ID:tomoya92,項目名稱:android-apps,代碼行數:33,代碼來源:NewsFragment.java

示例6: onCreate

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_oschina);

  toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setTitle(R.string.oschina);
  toolbar.setNavigationOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      OSChinaActivity.this.finish();
    }
  });

  tabLayout = (TabLayout) findViewById(R.id.tabLayout);
  viewPager = (ViewPager) findViewById(R.id.viewPager);

  tabLayout.addOnTabSelectedListener(this);
  viewPager.addOnPageChangeListener(this);

  viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
    @Override
    public Fragment getItem(int position) {
      switch (position) {
        case 0:
          return osChinaIndustryFragment;
        case 1:
          return osChinaProjectFragment;
      }
      return null;
    }

    @Override
    public int getCount() {
      return 2;
    }
  });

}
 
開發者ID:tomoya92,項目名稱:android-apps,代碼行數:40,代碼來源:OSChinaActivity.java

示例7: onCreate

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_v2ex);

  toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setTitle(R.string.v2ex);
  toolbar.setNavigationOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      V2exActivity.this.finish();
    }
  });

  tabLayout = (TabLayout) findViewById(R.id.tabLayout);
  viewPager = (ViewPager) findViewById(R.id.viewPager);

  tabLayout.addOnTabSelectedListener(this);
  viewPager.addOnPageChangeListener(this);

  viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
    @Override
    public Fragment getItem(int position) {
      switch (position) {
        case 0:
          return v2exLatestFragment;
        case 1:
          return v2exHotFragment;
      }
      return null;
    }

    @Override
    public int getCount() {
      return 2;
    }
  });

}
 
開發者ID:tomoya92,項目名稱:android-apps,代碼行數:40,代碼來源:V2exActivity.java

示例8: onCreate

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

	Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
	setSupportActionBar(toolbar);
	// Create the adapter that will return a fragment for each of the three
	// primary sections of the activity.
	mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

	// Set up the ViewPager with the sections adapter.
	mViewPager = (ViewPager) findViewById(R.id.container);
	mViewPager.setAdapter(mSectionsPagerAdapter);

	TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
	tabLayout.setupWithViewPager(mViewPager);

	tabLayout.addOnTabSelectedListener(onTabSelectedListener);
	mViewPager.addOnPageChangeListener(onPageChangeListener);

	fabAdd = (FloatingActionButton) findViewById(R.id.fab);
	fabAdd.hide();
	fabAdd.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View view) {
			Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
					.setAction("Action", null).show();
		}
	});

	// attempt extraction in activity, to make service start faster
	StunnelProcessManager.checkAndExtract(this);
	StunnelProcessManager.setupConfig(this);
}
 
開發者ID:comp500,項目名稱:SSLSocks,代碼行數:36,代碼來源:MainActivity.java

示例9: initTabs

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
public void initTabs(MainActivity mainActivity, Intent intent, TabLayout tabLayout) {
    mTabLayout = tabLayout;
    mInflater = LayoutInflater.from(AndFastApplication.getContext());
    tabLayout.addOnTabSelectedListener(getTabSelectedListener(mainActivity));

    MainTab[] mainTabs = MainTab.values();
    for (int i = 0; i < mainTabs.length; i++) {
        MainTab mainTab = mainTabs[i];
        mTabLayout.addTab(mTabLayout.newTab().setCustomView(getTabItemView(i, mainTab)).setTag(new TabInfo(mainTab.getClazz())), false);
    }
    changeTab(intent);
    mTabTextView[mLastIdx].setTextColor(AndFastApplication.getContext().getResources().getColor(R.color.colorPrimary));
}
 
開發者ID:bigjelly,項目名稱:ShaddockVideoPlayer,代碼行數:14,代碼來源:TabManager.java

示例10: initTabs

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
public void initTabs(MainActivity mainActivity,Intent intent,TabLayout tabLayout) {
    mTabLayout = tabLayout;
    mInflater = LayoutInflater.from(AndFastApplication.getContext());
    tabLayout.addOnTabSelectedListener(getTabSelectedListener(mainActivity));

    MainTab[] mainTabs = MainTab.values();
    for (int i = 0; i < mainTabs.length; i++) {
        MainTab mainTab = mainTabs[i];
        mTabLayout.addTab(mTabLayout.newTab().setCustomView(getTabItemView(i, mainTab)).setTag(new TabInfo(mainTab.getClazz())), false);
    }
    changeTab(intent);
    mTabTextView[mLastIdx].setTextColor(AndFastApplication.getContext().getResources().getColor(R.color.tab_font_red));
}
 
開發者ID:bigjelly,項目名稱:AndFast,代碼行數:14,代碼來源:TabManager.java

示例11: onCreate

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_segmentfault);

  toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setTitle(R.string.segmentfault);
  toolbar.setNavigationOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      SegmentFaultActivity.this.finish();
    }
  });

  tabLayout = (TabLayout) findViewById(R.id.tabLayout);
  viewPager = (ViewPager) findViewById(R.id.viewPager);

  tabLayout.addOnTabSelectedListener(this);
  viewPager.addOnPageChangeListener(this);

  viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
    @Override
    public Fragment getItem(int position) {
      switch (position) {
        case 0:
          return segmentFaultRecommendFragment;
        case 1:
          return segmentFaultNewestFragment;
        case 2:
          return segmentFaultHottestFragment;
      }
      return null;
    }

    @Override
    public int getCount() {
      return 3;
    }
  });

}
 
開發者ID:tomoya92,項目名稱:android-apps,代碼行數:42,代碼來源:SegmentFaultActivity.java

示例12: onCreate

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_tencentnews);

  toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setTitle(R.string.tencentnews);
  toolbar.setNavigationOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      TencentNewsActivity.this.finish();
    }
  });

  tabLayout = (TabLayout) findViewById(R.id.tabLayout);
  viewPager = (ViewPager) findViewById(R.id.viewPager);

  tabLayout.addOnTabSelectedListener(this);
  viewPager.addOnPageChangeListener(this);
  viewPager.setOffscreenPageLimit(3);
  viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
    @Override
    public Fragment getItem(int position) {
      switch (position) {
        case 0:
          return tencentNewsFragment;
        case 1:
          return tencentSheHuiFragment;
        case 2:
          return tencentMilFragment;
        case 3:
          return tencentHuaTiFragment;
      }
      return null;
    }

    @Override
    public int getCount() {
      return 4;
    }
  });

}
 
開發者ID:tomoya92,項目名稱:android-apps,代碼行數:44,代碼來源:TencentNewsActivity.java

示例13: onCreateView

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_detail, container, false);
    ((AppCompatActivity) getActivity()).setSupportActionBar(mBinding.detailToolbar);
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = mBinding.detailViewpagerContainer;
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = mBinding.tabs;

    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));

    if (savedInstanceState != null){
        if (savedInstanceState.containsKey(INGREDIENTS_STATE)){
            mIngredientsList = savedInstanceState.getParcelableArrayList(INGREDIENTS_STATE);
        }
        if (savedInstanceState.containsKey(STEPS_STATE)){
            mStepsList = savedInstanceState.getParcelableArrayList(STEPS_STATE);
        }
        if (savedInstanceState.containsKey("RECIPE_NAME")){
            recipeName = savedInstanceState.getString("RECIPE_NAME");
        }
        recipeId = savedInstanceState.getLong("RECIPE_ID");
    } else {
        Bundle args = getArguments();
        if (args != null) {
                recipeId = args.getLong("RECIPE_ID", -1);
                if (args.containsKey(IngredientsFragment.INGREDIENTS_EXTRA)) {
                    mIngredientsList = args.getParcelableArrayList(IngredientsFragment.INGREDIENTS_EXTRA);
                }
                if (args.containsKey(StepsFragment.STEPS_EXTRA)) {
                    mStepsList = args.getParcelableArrayList(StepsFragment.STEPS_EXTRA);
                }
                if (args.containsKey("RECIPE_NAME")){
                    recipeName = args.getString("RECIPE_NAME");
                    ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(recipeName);
                }
            }
        }
    return mBinding.getRoot();
}
 
開發者ID:harrynp,項目名稱:BakingApp,代碼行數:48,代碼來源:DetailFragment.java

示例14: onActivityCreated

import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    MainActivity activity = (MainActivity) getActivity();
    if (activity == null) throw new AssertionError("Activity is null");

    // MainActivity's layout is guaranteed to be inflated until onCreate returns.
    TabLayout layout = activity.findViewById(R.id.tab_layout);
    onTabSelectedListener = new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {}

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {}

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            jumpToTop();
        }
    };
    layout.addOnTabSelectedListener(onTabSelectedListener);

    /* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't
     * guaranteed to be set until then.
     * Use a modified scroll listener that both loads more notifications as it goes, and hides
     * the compose button on down-scroll. */
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
    preferences.registerOnSharedPreferenceChangeListener(this);
    hideFab = preferences.getBoolean("fabHide", false);
    scrollListener = new EndlessOnScrollListener(layoutManager) {
        @Override
        public void onScrolled(RecyclerView view, int dx, int dy) {
            super.onScrolled(view, dx, dy);

            ActionButtonActivity activity = (ActionButtonActivity) getActivity();
            FloatingActionButton composeButton = activity.getActionButton();

            if (composeButton != null) {
                if (hideFab) {
                    if (dy > 0 && composeButton.isShown()) {
                        composeButton.hide(); // hides the button if we're scrolling down
                    } else if (dy < 0 && !composeButton.isShown()) {
                        composeButton.show(); // shows it if we are scrolling up
                    }
                } else if (!composeButton.isShown()) {
                    composeButton.show();
                }
            }
        }

        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            NotificationsFragment.this.onLoadMore();
        }
    };

    recyclerView.addOnScrollListener(scrollListener);
}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:60,代碼來源:NotificationsFragment.java


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