本文整理汇总了Java中android.support.design.widget.TabLayout.setTabMode方法的典型用法代码示例。如果您正苦于以下问题:Java TabLayout.setTabMode方法的具体用法?Java TabLayout.setTabMode怎么用?Java TabLayout.setTabMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.design.widget.TabLayout
的用法示例。
在下文中一共展示了TabLayout.setTabMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
}
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
setupViewPager(viewPager);
// 设置ViewPager的数据等
tabLayout.setupWithViewPager(viewPager);
// tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);//适合很多tab
tabLayout.setTabMode(TabLayout.MODE_FIXED);//tab均分,适合少的tab
}
示例2: onViewCreated
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
ViewPager viewPager = view.findViewById(R.id.viewpager);
viewPager.setOffscreenPageLimit(1);
setupViewPager(viewPager);
TabLayout tabLayout = view.findViewById(R.id.tablayout);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
int tabColorPrimary = CurrentTheme.getPrimaryTextColorOnColoredBackgroundCode(getActivity());
int tabColorSecondary = CurrentTheme.getSecondaryTextColorOnColoredBackgroundCode(getActivity());
tabLayout.setTabTextColors(tabColorSecondary, tabColorPrimary);
tabLayout.setupWithViewPager(viewPager);
if(getArguments().containsKey(Extra.TAB)){
int tab = getArguments().getInt(Extra.TAB);
getArguments().remove(Extra.TAB);
viewPager.setCurrentItem(tab);
}
}
示例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);
}
示例4: init
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void init(){
addTapData();
viewPager = (MyViewPager)findViewById(R.id.local_viewPager);
tabLayout = (TabLayout)findViewById(R.id.local_tab);
fragmentAdapter = new MyAdapter(getSupportFragmentManager());
viewPager.setAdapter(fragmentAdapter);
viewPager.setOffscreenPageLimit(2); //预加载页面数
tabLayout.setTabMode(TabLayout.MODE_FIXED);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setupWithViewPager(viewPager);
nothingTv = (TextView)findViewById(R.id.local_nothing_tv);
nothingTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(LocalMusicActivity.this,ScanActivity.class);
startActivity(intent);
}
});
}
示例5: 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()));
}
示例6: onCreate
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_template);
ButterKnife.bind(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// 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.setTabMode(TabLayout.MODE_SCROLLABLE);
}
示例7: onCreateView
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tab_and_pager, container, false);
mTabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
mPager = (ViewPager) view.findViewById(R.id.pager);
ImageView mAdd = (ImageView) view.findViewById(R.id.add);
mFragments = new ArrayList<>();
mTabTittles = new ArrayList<>();
mAdapter = new PagerAdapter(getChildFragmentManager(), mTabTittles, mFragments);
initSharedPrefer();
// mTabTittles = (ArrayList<String>) Arrays.asList(getResources().getStringArray(R.array.DefaultTabTittles));
mPager.setAdapter(mAdapter);
setPageChangeListener();
mTabLayout.setupWithViewPager(mPager);
mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
mAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().startActivity(new Intent(getActivity(), AddTabsActivity.class));
getActivity().overridePendingTransition(R.anim.right_in, android.R.anim.fade_out);
}
});
return view;
}
示例8: dynamicSetTabLayoutMode
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
/**
* 动态修改tab的模式
*
* @param tabLayout tabLayout
*/
public static void dynamicSetTabLayoutMode(TabLayout tabLayout) {
int tabTotalWidth = 0;
for (int i = 0; i < tabLayout.getChildCount(); i++) {
final View view = tabLayout.getChildAt(i);
view.measure(0, 0);
tabTotalWidth += view.getMeasuredWidth();
}
if (tabTotalWidth <= MeasureUtils.getScreenSize(tabLayout.getContext()).x) {
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
} else {
tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}
}
示例9: initTab
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
public void initTab(TabLayout tabLayout) {
tabLayout.setTabMode(TabLayout.MODE_FIXED);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setBackgroundColor(getContext().getResources().getColor(R.color.colorPrimary));
tabLayout.setSelectedTabIndicatorColor(Color.WHITE);
tabLayout.setTabTextColors(ColorStateList.valueOf(Color.WHITE));
}
示例10: initTabLayout
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initTabLayout(View view) {
TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewPager);
setupViewPager(viewPager);
viewPager.setOffscreenPageLimit(viewPager.getAdapter().getCount());
// 设置ViewPager的数据等
tabLayout.setupWithViewPager(viewPager);
//适合很多tab
//tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
//tab均分,适合少的tab
tabLayout.setTabMode(TabLayout.MODE_FIXED);
//tab均分,适合少的tab,TabLayout.GRAVITY_CENTER
//tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
}
示例11: dynamicSetTabLayoutMode
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
public static void dynamicSetTabLayoutMode(TabLayout tabLayout) {
int tabWidth = calculateTabWidth(tabLayout);
int screenWidth = getScreenWith();
if (tabWidth <= screenWidth) {
tabLayout.setTabMode(TabLayout.MODE_FIXED);
} else {
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}
}
示例12: onCreate
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_utril_view);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mFragments.add(new RecyclerViewFragment());
mFragments.add(new ListViewFragment());
mFragments.add(new ScrollViewFragment());
mFragments.add(new WebViewFragment());
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), mFragments);
// 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.setTabMode(TabLayout.MODE_SCROLLABLE);
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();
}
});
}
示例13: initTabLayout
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initTabLayout() {
TabLayout tabLayout = findView(R.id.tabs);
ViewPager viewPager = findView(R.id.viewPager);
setupViewPager(viewPager);
viewPager.setOffscreenPageLimit(viewPager.getAdapter().getCount());
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}
示例14: initTabLayout
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initTabLayout(List<XianduCategory> xianduCategories) {
TabLayout tabLayout = findView(R.id.tabs);
ViewPager viewPager = findView(R.id.viewPager);
setupViewPager(viewPager, xianduCategories);
viewPager.setOffscreenPageLimit(viewPager.getAdapter().getCount());
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}
示例15: initTabLayout
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initTabLayout() {
TabLayout tabLayout = findView(R.id.tabs);
ViewPager viewPager = findView(R.id.viewPager);
setupViewPager(viewPager);
viewPager.setOffscreenPageLimit(viewPager.getAdapter().getCount());
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
}