标签与Android的设计库使用TabLayout图标 [英] Tab with icon using TabLayout in Android Design Library

查看:788
本文介绍了标签与Android的设计库使用TabLayout图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用新TabLayout在android设计库创建的图标应用栏只。

I'm trying to use the new TabLayout in the android design library to create app bar with icons only.

是这样的:

like this:

我怎么能做到这一点使用新的TabLayout Android的设计库。

how can I do it using the new TabLayout Android Design Library.

是有一个简单的解决方案,或者我必须只使用setCustomView。我试图避免使用它。因为我没有得到色调色像上面这个图片的图标。

is there a simple solution for this, or i have to use the setCustomView only. i'm trying to avoid using it. because i didn't get the tint color for the icon like this image above.

我尝试写这样的:

tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.ic_dashboard))

但是图标还停留在相同的颜色时,我选择的标签

but the icon still stay in the same color when i select the tab

推荐答案

我解决了这个问题是这样的:

i solved it like this:

tint_tab.xml

tint_tab.xml

<com.hannesdorfmann.appkit.image.TintableImageView
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 app:tint="@color/tab_color_selector"/>

在你的java code

in you java code

TintableImageView tab1 = (TintableImageView) LayoutInflater.from(this).inflate(R.layout.tint_tab, null);
tab1.setImageResource(R.drawable.ic_dummy);
mTabLayout.getTabAt(0).setCustomView(tab1)

REF:<一href="https://github.com/sockeqwe/appkit/blob/master/image/src/main/java/com/hannesdorfmann/appkit/image/TintableImageView.java" rel="nofollow">https://github.com/sockeqwe/appkit/blob/master/image/src/main/java/com/hannesdorfmann/appkit/image/TintableImageView.java

这篇关于标签与Android的设计库使用TabLayout图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆