本文整理汇总了Java中android.support.design.widget.TabLayout.addTab方法的典型用法代码示例。如果您正苦于以下问题:Java TabLayout.addTab方法的具体用法?Java TabLayout.addTab怎么用?Java TabLayout.addTab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.design.widget.TabLayout
的用法示例。
在下文中一共展示了TabLayout.addTab方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTabLayout
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@NonNull
private TabLayout setTabLayout(View view) {
TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout_rewards);
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.available_rewards_tab)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.exchanged_rewards_tab)));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(),
"fonts/Nunito-Regular.ttf");
ViewGroup viewGroup = (ViewGroup) tabLayout.getChildAt(0);
for (int i = 0; i < 2; i++) {
AppCompatTextView appCompatTextView = (AppCompatTextView) ((ViewGroup) viewGroup
.getChildAt(i)).getChildAt(1);
appCompatTextView.setTypeface(typeface, Typeface.NORMAL);
}
return tabLayout;
}
示例2: initUI
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
/**
* 初始化界面
*/
private void initUI() {
tabLayout= (TabLayout) findViewById(R.id.tab_layout);
viewPager= (ViewPager) findViewById(R.id.view_pager);
tabLayout.addTab(tabLayout.newTab().setText(titleList[0]));
tabLayout.addTab(tabLayout.newTab().setText(titleList[1]));
deviceListFragment=new DeviceListFragment();
dataTransFragment=new DataTransFragment();
fragmentList.add(deviceListFragment);
fragmentList.add(dataTransFragment);
pagerAdapter=new MyPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(pagerAdapter);
tabLayout.setupWithViewPager(viewPager);
}
示例3: 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;
}
示例4: initView
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
protected void initView() {
findViewById(R.id.iv_github).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openMyGitHub();
}
});
mPagerBehavior = (UcNewsHeaderPagerBehavior) ((CoordinatorLayout.LayoutParams) findViewById(R.id.id_uc_news_header_pager).getLayoutParams()).getBehavior();
mPagerBehavior.setPagerStateListener(this);
mNewsPager = (ViewPager) findViewById(R.id.id_uc_news_content);
mTableLayout = (TabLayout) findViewById(R.id.id_uc_news_tab);
mFragments = new ArrayList<TestFragment>();
for (int i = 0; i < 4; i++) {
mFragments.add(TestFragment.newInstance(String.valueOf(i), false));
mTableLayout.addTab(mTableLayout.newTab().setText("Tab" + i));
}
mTableLayout.setTabMode(TabLayout.MODE_FIXED);
mTableLayout.setOnTabSelectedListener(this);
mNewsPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTableLayout));
mNewsPager.setAdapter(new TestFragmentAdapter(mFragments, getSupportFragmentManager()));
}
示例5: findViews
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void findViews() {
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(this);
mLayout = (RelativeLayout) findViewById(R.id.layout_chat_empty);
mTabLayout = (TabLayout) findViewById(R.id.tabLayout);
mTabLayout.addTab(mTabLayout.newTab().setText("Public"));
mTabLayout.addTab(mTabLayout.newTab().setText("Private"));
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
toolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_layout);
toolbarParams = (AppBarLayout.LayoutParams) toolbarLayout.getLayoutParams();
setSupportActionBar(mToolbar);
mTextOnToolbar = (TextView) findViewById(R.id.chat_toolbar_title);
mNavigationView = (NavigationView) findViewById(R.id.nav_view);
progressBar = (ProgressBar) findViewById(R.id.main_progress_bar);
progressBar.getIndeterminateDrawable()
.setColorFilter(getResources().getColor(R.color.colorPrimary), android.graphics.PorterDuff.Mode.MULTIPLY);
}
示例6: initViewPager
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initViewPager() {
mTabLayout = (TabLayout) findViewById(R.id.tabs);
List<String> titles = new ArrayList<>();
titles.add("精选");
titles.add("体育");
titles.add("巴萨");
titles.add("购物");
titles.add("明星");
titles.add("视频");
titles.add("健康");
titles.add("励志");
titles.add("图文");
titles.add("本地");
titles.add("动漫");
titles.add("搞笑");
titles.add("精选");
for (int i = 0; i < titles.size(); i++) {
mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
}
List<Fragment> fragments = new ArrayList<>();
for (int i = 0; i < titles.size(); i++) {
fragments.add(new ListFragment());
}
FragmentAdapter mFragmentAdapteradapter =
new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
//给ViewPager设置适配器
mViewPager.setAdapter(mFragmentAdapteradapter);
//将TabLayout和ViewPager关联起来。
mTabLayout.setupWithViewPager(mViewPager);
//给TabLayout设置适配器
mTabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);
}
示例7: initViewPager
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initViewPager() {
mTabLayout = (TabLayout) findViewById(R.id.tabs);
List<String> titles = new ArrayList<>();
titles.add("精选");
titles.add("体育");
titles.add("巴萨");
titles.add("购物");
titles.add("明星");
titles.add("视频");
titles.add("健康");
titles.add("励志");
titles.add("图文");
titles.add("本地");
titles.add("动漫");
titles.add("搞笑");
titles.add("精选");
for (int i = 0; i < titles.size(); i++) {
mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
}
List<Fragment> fragments = new ArrayList<>();
for (int i = 0; i < titles.size(); i++) {
fragments.add(new ListFragment());
}
FragmentAdapter mFragmentAdapteradapter =
new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
//给ViewPager设置适配器
mViewPager.setAdapter(mFragmentAdapteradapter);
//将TabLayout和ViewPager关联起来。
mTabLayout.setupWithViewPager(mViewPager);
//给TabLayout设置适配器
mTabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);
}
示例8: initializeViews
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
/**
* Initialize recyclerview and adapters.
* call adapter.notifyDataSetChanged if the realm for currency is updated
* */
private void initializeViews(View rootView) {
fab=(FloatingActionButton)rootView.findViewById(R.id.fab);
tabLayout=(TabLayout)rootView.findViewById(R.id.tabs);
viewPager=(ViewPager) rootView.findViewById(R.id.container);
for (Site title:sites
) {
TabLayout.Tab tab=tabLayout.newTab();
tab.setText(title.getName());
tabLayout.addTab(tab);
}
tabLayout.setupWithViewPager(viewPager);
}
示例9: initView
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
public void initView() {
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
viewPager = (ViewPager) findViewById(R.id.viewPager);
tabLayout.addTab(tabLayout.newTab().setText(titles[0]));
tabLayout.addTab(tabLayout.newTab().setText(titles[1]));
viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(),fragments,titles));
tabLayout.setupWithViewPager(viewPager);
}
示例10: initView
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initView() {
viewPager = (ViewPager) findViewById(R.id.fl_vp);
tabLayout = (TabLayout) findViewById(R.id.fl_tab);
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
}
示例11: InitView
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void InitView() {
mTabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
mViewPager = (ViewPager) rootView.findViewById(viewpager);
//初始化TabLayout的title
mTabLayout.addTab(mTabLayout.newTab().setText("工作"));
mTabLayout.addTab(mTabLayout.newTab().setText("上研"));
mTabLayout.addTab(mTabLayout.newTab().setText("期末"));
mTabLayout.addTab(mTabLayout.newTab().setText("四六级"));
List<String> titles = new ArrayList<>();
titles.add("工作");
titles.add("上研");
titles.add("期末");
titles.add("四六级");
//初始化ViewPager的数据集
List<Fragment> fragments = new ArrayList<>();
fragments.add(new SecondSubFragment().newInstance("Job"));
fragments.add(new SecondSubFragment().newInstance("Postgraduate"));
fragments.add(new SecondSubFragment().newInstance("Terminal"));
fragments.add(new SecondSubFragment().newInstance("CET"));
//创建ViewPager的adapter
FragmentAdapter adapter = new FragmentAdapter(getChildFragmentManager(), fragments, titles);
mViewPager.setAdapter(adapter);
//千万别忘了,关联TabLayout与ViewPager
//同时也要覆写PagerAdapter的getPageTitle方法,否则Tab没有title
mTabLayout.setupWithViewPager(mViewPager);
// mTabLayout.setTabsFromPagerAdapter(adapter);
}
示例12: onCreate
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "Package Name - " + getApplicationContext().getPackageName());
// Create a new dispatcher using the Google Play driver.
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job myJob = dispatcher.newJobBuilder()
.setService(MonolithFetchService.class)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(SYNC_INTERVAL, SYNC_INTERVAL + SYNC_FLEXTIME))
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.setTag("update-job")
.setConstraints(Constraint.ON_ANY_NETWORK)
.setLifetime(Lifetime.FOREVER)
.build();
dispatcher.mustSchedule(myJob);
// Obtain the FirebaseAnalytics instance.
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
// Create the adapter that will return a fragment for each of the two
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(),
tabLayout.getTabCount());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setupWithViewPager(mViewPager);
}