android tablayout 图标,android – 如何增加TabLayout中标签的图标大小

这篇博客介绍了如何解决在Android应用中自定义TabLayout选项卡的问题。通过创建名为customtab.xml的布局文件,设置垂直方向,并在每个选项卡中使用(setCustomView)方法,结合getLayoutInflater()来加载布局并设置图片资源。这种方法允许开发者为每个Tab设置不同的背景图片,例如my1、my2和my3。
摘要由CSDN通过智能技术生成

嗨,我面临同样的问题,这是我能找到的最好的解决方案:

您应该使用(setCustomView),首先创建一个新的布局文件

让它命名(customtab.xml):

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:scaleType="fitCenter"

android:id="@+id/icon"

android:layout_gravity="center_horizontal" />

然后为每个选项卡执行此操作:(使用相同的布局.xml)

View view1 = getLayoutInflater().inflate(R.layout.customtab, null);

view1.findViewById(R.id.icon).setBackgroundResource(R.drawable.my1);

tabLayout.addTab(tabLayout.newTab().setCustomView(view1));

View view2 = getLayoutInflater().inflate(R.layout.customtab, null);

view2.findViewById(R.id.icon).setBackgroundResource(R.drawable.my2);

tabLayout.addTab(tabLayout.newTab().setCustomView(view2));

View view3 = getLayoutInflater().inflate(R.layout.customtab, null);

view3.findViewById(R.id.icon).setBackgroundResource(R.drawable.my3);

tabLayout.addTab(tabLayout.newTab().setCustomView(view3));

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值