当前位置: 首页>>代码示例>>Java>>正文


Java TabLayout.getChildAt方法代码示例

本文整理汇总了Java中android.support.design.widget.TabLayout.getChildAt方法的典型用法代码示例。如果您正苦于以下问题:Java TabLayout.getChildAt方法的具体用法?Java TabLayout.getChildAt怎么用?Java TabLayout.getChildAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.design.widget.TabLayout的用法示例。


在下文中一共展示了TabLayout.getChildAt方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:20,代码来源:AwardsFragment.java

示例2: 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);
    }
}
 
开发者ID:shenhuanet,项目名称:OpenEyesReading-android,代码行数:21,代码来源:SinaPhotoActivity.java

示例3: calculateTabWidth

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private static int calculateTabWidth(TabLayout tabLayout) {
    int tabWidth = 0;
    for (int i = 0; i < tabLayout.getChildCount(); i++) {
        final View view = tabLayout.getChildAt(i);
        view.measure(0, 0); // 通知父view测量,以便于能够保证获取到宽高
        tabWidth += view.getMeasuredWidth();
    }
    return tabWidth;
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:10,代码来源:MyUtils.java

示例4: makTabsFixed

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void makTabsFixed(TabLayout tabLayout) {
    ViewGroup slidingTabStrip = (ViewGroup) tabLayout.getChildAt(0);
    int tabCount = tabLayout.getTabCount();
    for (int i = 0; i < tabCount; i++) {
        View tab = slidingTabStrip.getChildAt(i);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) tab.getLayoutParams();
        layoutParams.weight = 1;
        tab.setLayoutParams(layoutParams);
    }
}
 
开发者ID:fekracomputers,项目名称:IslamicLibraryAndroid,代码行数:11,代码来源:LibraryFragment.java

示例5: changeTabsFont

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
public static void changeTabsFont(Context context, TabLayout mTabs) {
    Common common = (Common) context.getApplicationContext();
    ViewGroup vg = (ViewGroup) mTabs.getChildAt(0);
    int tabsCount = vg.getChildCount();
    for (int j = 0; j < tabsCount; j++) {
        ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
        int tabChildsCount = vgTab.getChildCount();
        for (int i = 0; i < tabChildsCount; i++) {
            View tabViewChild = vgTab.getChildAt(i);
            if (tabViewChild instanceof TextView) {
                ((TextView) tabViewChild).setTypeface(TypefaceHelper.getTypeface(context, TypefaceHelper.FUTURA_BOLD));
            }
        }
    }
}
 
开发者ID:reyanshmishra,项目名称:Rey-MusicPlayer,代码行数:16,代码来源:MusicUtils.java

示例6: onCreate

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_layout);
        mTabLayout = (TabLayout) findViewById(R.id.tabLayout);

        // 手动创建Tab
//        for (int i = 0; i < title.length; i++) {
//            TabLayout.Tab tab = mTabLayout.newTab();
//            tab.setText(title[i]);
////            tab.setIcon(R.mipmap.ic_launcher);//icon会显示在文字上面
//            mTabLayout.addTab(tab);
//        }

        // TabLayout与ViewPager结合使用
        mViewPager = (ViewPager) findViewById(R.id.viewPager);
        MyViewPagerAdapter adapter = new MyViewPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(adapter);
//        // 适配器必须重写getPageTitle()方法
//        mTabLayout.setTabsFromPagerAdapter(adapter);
//        // 监听TabLayout的标签选择,当标签选中时ViewPager切换
//        mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
//        // 监听ViewPager的页面切换,当页面切换时TabLayout的标签跟着切换
//        mViewPager.setOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
        // 关联TabLayout与ViewPager,且适配器必须重写getPageTitle()方法
        mTabLayout.setupWithViewPager(mViewPager);


        mLinearLayout = (LinearLayout) mTabLayout.getChildAt(0);
        // 在所有子控件的中间显示分割线(还可能只显示顶部、尾部和不显示分割线)
        mLinearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        // 设置分割线的距离本身(LinearLayout)的内间距
        mLinearLayout.setDividerPadding(50);
        // 设置分割线的样式
        mLinearLayout.setDividerDrawable(ContextCompat.getDrawable(this, R.drawable.divider_vertical));
        mLinearLayout.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));


        // 为TabLayout设置不同状态下的字体大小(并不能成功)
//        for (int i = 0; i < mTabLayout.getTabCount(); i++) {
//            ((TextView) ((LinearLayout) mLinearLayout.getChildAt(i)).getChildAt(1)).setTextSize(10);
////            ((TextView) ((LinearLayout) ((LinearLayout) mTabLayout.getChildAt(0)).getChildAt(i)).getChildAt(0)).setTextSize(12);
//        }
//        ((TextView) ((LinearLayout) mLinearLayout.getChildAt(mTabLayout.getSelectedTabPosition())).getChildAt(1)).setTextSize(30);
//
//        mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
//            @Override
//            public void onTabSelected(TabLayout.Tab tab) {
//                ((TextView) ((LinearLayout) mLinearLayout.getChildAt(tab.getPosition())).getChildAt(1)).setTextSize(30);
//            }
//
//            @Override
//            public void onTabUnselected(TabLayout.Tab tab) {
//                ((TextView) ((LinearLayout) mLinearLayout.getChildAt(tab.getPosition())).getChildAt(1)).setTextSize(10);
//            }
//
//            @Override
//            public void onTabReselected(TabLayout.Tab tab) {
//
//            }
//        });


        // 自定义指示器(Indicator)的“长度”的两种方法
        // 方法一:反射
//        setIndicator(mTabLayout,10,10);
        // 方法二:查找子控件
        int left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, Resources.getSystem().getDisplayMetrics());
        int right = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, Resources.getSystem().getDisplayMetrics());
        for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
            View tabView = mLinearLayout.getChildAt(0);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1);
            params.leftMargin = left;
            params.rightMargin = right;
            tabView.setLayoutParams(params);
        }
    }
 
开发者ID:GitLqr,项目名称:MaterialDesignDemo,代码行数:78,代码来源:TabLayoutActivity.java


注:本文中的android.support.design.widget.TabLayout.getChildAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。