安卓(Android)TabLayout点击字体变大

1.TabLayou本事自己是没有该属性的,所以我们就需要用到自定义布局,创建一个xml布局,布局里编写一个TextView。

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:textSize="30dp"
    android:textStyle="bold"
    android:gravity="center"
    android:text="66666"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

</TextView>

 2.然后就获取TabLayout的id

 fragmentOneTab = (TabLayout) findViewById(R.id.fragment_one_tab);

3.然后用获取到的id点击方法

 fragmentOneTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
                //选中
            @Overrid
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Android TabLayout上设置字体,你可以使用自定义的TabLayout.TabCustomView来实现。以下是一个示例代码: 首先,在res/layout目录下创建一个自定义的tab_item.xml文件,用于定义TabLayout中每个标签的样式,可以在此文件中设置字体样式。 ```xml <!-- tab_item.xml --> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tab_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" android:textColor="@color/tab_text_color" android:fontFamily="@font/custom_font" /> ``` 接下来,在你的Activity或Fragment中,使用以下代码来设置TabLayout的标签视图: ```java // 获取TabLayout对象 TabLayout tabLayout = findViewById(R.id.tab_layout); // 添加标签 tabLayout.addTab(tabLayout.newTab().setCustomView(R.layout.tab_item)); // 设置标签文本 TextView tabText = tabLayout.getTabAt(0).getCustomView().findViewById(R.id.tab_text); tabText.setText("标签1"); ``` 在上面的代码中,你可以看到通过调用`setCustomView()`方法来设置自定义的布局文件作为标签视图。然后,我们可以通过`getCustomView()`方法获取自定义视图,并使用findViewById()来找到TextView并设置文本。 请注意,你需要将自定义字体文件放在res/font目录下,并将其引用到tab_item.xml中的`android:fontFamily`属性中。 这样就可以在Android TabLayout上设置字体了。你可以根据需要自定义标签视图,并在其中设置不同的字体样式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值