本文整理汇总了Java中android.support.design.widget.TabLayout.setTabGravity方法的典型用法代码示例。如果您正苦于以下问题:Java TabLayout.setTabGravity方法的具体用法?Java TabLayout.setTabGravity怎么用?Java TabLayout.setTabGravity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.design.widget.TabLayout
的用法示例。
在下文中一共展示了TabLayout.setTabGravity方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateView
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.activity_dual_tab_photos, container, false);
((AppCompatActivity) getActivity()).setSupportActionBar(root.findViewById(R.id.toolbar));
TabLayout tabLayout = root.findViewById(R.id.tablayout);
tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
int tabColorPrimary = CurrentTheme.getPrimaryTextColorOnColoredBackgroundCode(getActivity());
int tabColorSecondary = CurrentTheme.getSecondaryTextColorOnColoredBackgroundCode(getActivity());
tabLayout.setTabTextColors(tabColorSecondary, tabColorPrimary);
ViewPager viewPager = root.findViewById(R.id.view_pager);
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
@Override
public void onPageSelected(int position) {
mCurrentTab = position;
}
});
mPagerAdapter = new Adapter(getChildFragmentManager(), mSources);
viewPager.setAdapter(mPagerAdapter);
tabLayout.setupWithViewPager(viewPager, true);
return root;
}
示例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: 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;
}
示例4: onCreateView
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.content_notifications, container, false);
AppBarLayout appBarLayout = getActivity().findViewById(R.id.appbar);
if (appBarLayout.getChildCount() == 1) {
mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
mViewPager = rootView.findViewById(R.id.tab_container);
mViewPager.setAdapter(mSectionsPagerAdapter);
mTabLayout = new TabLayout(getActivity());
mTabLayout.setTabTextColors(
getResources().getColor(R.color.disabledGrey),
getResources().getColor(R.color.white)
);
mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
mTabLayout.setupWithViewPager(mViewPager);
appBarLayout.addView(mTabLayout);
}
return rootView;
}
示例5: 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);
}
});
}
示例6: 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);
}
}
示例7: 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));
}
示例8: onViewCreated
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
ViewPager viewPager = view.findViewById(R.id.fragment_videos_pager);
setupViewPager(viewPager);
TabLayout tabLayout = view.findViewById(R.id.fragment_videos_tabs);
tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
int tabColorPrimary = CurrentTheme.getPrimaryTextColorOnColoredBackgroundCode(getActivity());
int tabColorSecondary = CurrentTheme.getSecondaryTextColorOnColoredBackgroundCode(getActivity());
tabLayout.setTabTextColors(tabColorSecondary, tabColorPrimary);
tabLayout.setupWithViewPager(viewPager);
}