本文整理匯總了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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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));
}
}
}
}
示例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);
}
}