gpt4 book ai didi

安卓 : How to create TabLayout with drawable for count textview?

转载 作者:行者123 更新时间:2023-11-29 01:12:41 26 4
gpt4 key购买 nike

  • 我正在尝试使用 android 设计库中的新 TabLayout

  • 我想创建一个 TextView,在选项卡上将可绘制对象作为背景的 TabLayout

  • 例如

    我在搜索框中搜索洛杉矶我应该在 TextView 中获取 Books,Movie,Place 的数量。

示例图片:

Example image

最佳答案

引用此链接将图标+文本添加到 TabLayout https://guides.codepath.com/android/Google-Play-Style-Tabs-using-TabLayout#add-icons-text-to-tablayout

还有这个

https://gist.github.com/kevinpelgrims/8685c8e1a68e3cd9cff9

    @Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
Drawable image = context.getResources().getDrawable(imageResId[position]);
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
// Replace blank spaces with image icon
SpannableString sb = new SpannableString(" " + tabTitles[position]);
ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb;
}

关于安卓 : How to create TabLayout with drawable for count textview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41828765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com