com.google.android.material.tabs.TabLayout 选择tab 加粗字体加大

Haidee ·
更新时间:2024-09-20
· 820 次阅读

引用: https://blog.csdn.net/qq_34906385/article/details/93524163 app:tabIndicatorColor :指示线的颜色 app:tabIndicatorHeight : 指示线的高度 app:tabIndicatorFullWidth="false" 指示线是否铺满宽度 app:tabSelectedTextColor : tab选中时的字体颜色 app:tabTextColor="@color/colorPrimary" :未选中字体颜色 app:tabBackground="color" : 整个tablayout颜色 app:tabMode="scrollable" : 默认是fixed,固定的;scrollable:可滚动的 //监听一定要在setupWithViewPager方法之前添加 binding.tablayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { changeTabTextView(tab, true); } @Override public void onTabUnselected(TabLayout.Tab tab) { changeTabTextView(tab, false); } @Override public void onTabReselected(TabLayout.Tab tab) { } }); // 选中第一个 changeTabTextView(binding.tablayout.getTabAt(0), true); /** * 字体加粗变颜色 * * @param tab * @param isBold */ public void changeTabTextView(TabLayout.Tab tab, boolean isBold) { View view = tab.getCustomView(); if (null == view) { tab.setCustomView(R.layout.tab_layout_text); } TextView textView = tab.getCustomView().findViewById(android.R.id.text1); if (isBold) { textView.setTextAppearance(context, R.style.TabLayoutBoldTextSize); } else { textView.setTextAppearance(context, R.style.TabLayoutNormalTextSize); } } 17sp bold #fc5a44 15sp normal #24272E
作者:Liuyz0420



com google 字体 tablayout material tabs Android

需要 登录 后方可回复, 如果你还没有账号请 注册新账号