我是靠谱客的博主 俊逸招牌,这篇文章主要介绍android 字体选中加粗,Android TabLayout选中字体加粗,现在分享给大家,希望可以做个参考。

解决办法是为TabLayout 添加一个监听,并在监听中自定义选中项UI,代码和布局文件如下

tablayoutTablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

@Override

public void onTabSelected(TabLayout.Tab tab) {

View view = tab.getCustomView();

if (null == view) {

tab.setCustomView(R.layout.custom_tab_layout_text);

}

TextView textView = tab.getCustomView().findViewById(android.R.id.text1);

textView.setTextColor(tablayoutTablayout.getTabTextColors());

textView.setTypeface(Typeface.DEFAULT_BOLD);

}

@Override

public void onTabUnselected(TabLayout.Tab tab) {

View view = tab.getCustomView();

if (null == view) {

tab.setCustomView(R.layout.custom_tab_layout_text);

}

TextView textView = tab.getCustomView().findViewById(android.R.id.text1);

textView.setTypeface(Typeface.DEFAULT);

}

@Override

public void onTabReselected(TabLayout.Tab tab) {

}

});

用到的布局文件如下

android:id="@android:id/text1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center"

/>

如果需要联合使用Fragment

需要注意的是 监听一定要在setupWithViewPager方法之前添加,否则会有bug

最后

以上就是俊逸招牌最近收集整理的关于android 字体选中加粗,Android TabLayout选中字体加粗的全部内容,更多相关android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(98)

评论列表共有 0 条评论

立即
投稿
返回
顶部