Tab with icon using TabLayout in Android Design Library

后端 未结 3 1955
北荒
北荒 2021-02-06 01:29

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

like this: \"

相关标签:
3条回答
  • 2021-02-06 01:40

    I used it like this: created an xml file in drawable as shown by @Budius.

    in the code: tabLayout.getTabAt(0).setIcon(R.drawable.settings_tab_drawable);

    and so on.

    0 讨论(0)
  • 2021-02-06 01:49

    i solved it like this:

    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"/>
    

    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: https://github.com/sockeqwe/appkit/blob/master/image/src/main/java/com/hannesdorfmann/appkit/image/TintableImageView.java

    0 讨论(0)
  • 2021-02-06 01:52

    you have to create a selector for the icon. For example:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/ic_dashboard_pressed"
              android:state_pressed="true" />
        <item android:drawable="@drawable/ic_dashboard_selected"
              android:state_selected="true" />
        <item android:drawable="@drawable/ic_dashboard_normal" />
    </selector>
    
    0 讨论(0)
提交回复
热议问题