实现 TabLayout 选中tab标签字体加粗功能如下:

xml文件中定义:

 <android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:tabIndicatorColor="@color/orange"
app:tabIndicatorHeight="2dp"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/_333333"
app:tabTextColor="@color/_4c4c4c"
app:tabTextAppearance="@style/TabLayoutStyle"/>
<style name="TabLayoutStyle">
<item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item>
</style>

java文件中设置:

//引用tablayout
ArrayList<String> tabList = new ArrayList<>();
tabList.add("tab1");

tabList.add("tab2");
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText(tabList.get(0));
tabLayout.addTab(tabLayout.newTab().setText(tabList.get(1))); for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
if (tab != null) {
tab.setCustomView(getTabView(i));
}
}
updateTabTextView(tabLayout.getTabAt(tabLayout.getSelectedTabPosition()), true); tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
updateTabView(tab, true); } @Override
public void onTabUnselected(TabLayout.Tab tab) {
updateTabView(tab, false);
} @Override
public void onTabReselected(TabLayout.Tab tab) { }
});
} private View getTabView(int currentPosition) {
View view = LayoutInflater.from(this).inflate(R.layout.tab_item, null);
TextView textView = (TextView) view.findViewById(R.id.tab_item_textview);
textView.setText(tabList.get(currentPosition));
return view;
} private void updateTabTextView(TabLayout.Tab tab, boolean isSelect) { if (isSelect) {
//选中加粗
TextView tabSelect = (TextView) tab.getCustomView().findViewById(R.id.tab_item_textview);
tabSelect.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
tabSelect.setText(tab.getText());
} else {
TextView tabUnSelect = (TextView) tab.getCustomView().findViewById(R.id.tab_item_textview);
tabUnSelect.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
tabUnSelect.setText(tab.getText());
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <TextView
android:id="@+id/tab_item_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/333333"
/> </LinearLayout>

 

android TabLayout设置选中标签字体加粗功能的更多相关文章

  1. css点击li里面的标签 点击当前标签字体加粗 之前的恢复原始状态

    <div class="functionalNavigation"> <ul class="ulp"> <icon class=& ...

  2. android textview字体加粗 Android studio最新水平居中和垂直居中

    android textview字体加粗 Android studio最新水平居中和垂直居中 Android中字体加粗在xml文件中使用android:textStyle=”bold”但是不能将中文设 ...

  3. html小知识点汇总(浏览器导航上显示图标、div无高度时试着清除浮动、文字环绕图片、字体加粗、div按百分比分、已有的不合适的class,针对特定的标签进行修改)

    1.新点击的网页,在浏览器导航上显示图标: 像这种效果: <head> <meta charset="UTF-8"> <meta name=" ...

  4. html字体加粗标签与写法

    在html中字体加粗的标签为<b>标签,当我们使用了该标签,字体就会加粗,一般用于注明重要信息,强调文字上面写法如下 字体加粗:<b>这里的字体就会加粗</b> 效 ...

  5. richTextBox设置选中的字体属性

      执行一次设置选中的字体样式 再执行一次恢复正常     //粗体 public void ToggleBold() { if (richTextBox1.SelectionFont == null ...

  6. HTML怎么实现字体加粗

    HTML的加粗标签是<b>标签,是用来对你自定文字加粗,写法如下: 字体加粗:<b>这里是加粗的内容</b> 这样就可以实现加粗了!

  7. C# DataGrid根据某列的内容设置行字体加粗 单元格设置对齐方式

    最近做了个功能,DataGrid显示具体内容的时候,根据某列分组. 每个分组具体内容后边,增加一行显示合计信息. 查询数据时,使用了union all将分组数据与明细数据合并起来,使用了排序达到了预期 ...

  8. Android TextView中 字体加粗方法

    textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗 textView.getPaint().setFakeBoldT ...

  9. UILabel字体加粗等属性和特效

    /* Accessing the Text Attributes text  property font  property textColor  property textAlignment  pr ...

随机推荐

  1. zabbix问题-非常少的网络故障失败或罕见:Proxy超时的问题

    解决方案 在zabbix_agentd.conf中添加这些. BufferSend = 10 BufferSize = 150 MaxLinesPerSecond = 100 Timeout = 29 ...

  2. wxWidgets 和 QT 之间的选择

    (非原创,网络摘抄) 跨平台的C++ GUI工具库很多,可是应用广泛的也就那么几个,Qt.wxWidgets便是其中的翘楚这里把GTK+排除在外,以C实现面向对象,上手相当困难,而且Windows平台 ...

  3. Python第二天: 变量详解及变量赋值

    目录 什么是变量? 怎么写一个好的变量? 下划线命名法及驼峰命名法 结语 目录 此文章针对刚学Python的小白,若觉得对变量有很好的掌握,可以观看其他的文章 在这里, 我说一下我对变量的简单总结: ...

  4. C# PDF转Image图片

    概述 PDF是常用的文件格式之一,通常情况下,我们可以使用itextsharp生产PDF文件:可是如何将PDF文件转换成图片那?目前常用的: 思路1.根据PDF绘画轨迹重新绘制图片: 思路2.是将PD ...

  5. go语言-值类型与引用类型

    https://www.cnblogs.com/java-zhao/p/9942311.html https://blog.csdn.net/TDCQZD/article/details/826836 ...

  6. 三种dedecms友情链接调用标签

    三种dedecms友情链接调用标签: 1.获取友情链接分类 {dede:flinktype}<span>[field:typename/]</span>{/dede:flink ...

  7. PS制作科幻特效的金色立体文字

    最终效果 一.Photoshop打开背景素材. 二.然后我们来制作字效,首先当然是在画布上打上字了,在这里要注意的是尽量选一些艺术字体,这样做出来的效果比较好些,我这里用到的字体为“Matura MT ...

  8. css3 animation(左右摆动) (放大缩小)

    左右摆动: @-webkit-keyframes roundRule{ 0%, 100%{ -webkit-transform: rotate(-15deg); } 50%{ -webkit-tran ...

  9. excel冻结标题栏,让标题栏不滚动的方法

    https://jingyan.baidu.com/article/148a1921f54afe4d71c3b18e.html

  10. 【数学建模】MATLAB语法

    一.向量.矩阵的表示和使用 format long  %小数很多format short %默认4位小数format rat %显示最近的分数format short e %指数格式的数 尾数多少 e ...