How to create app bar with icons using TabLayout Android Design?

前端 未结 4 1172
小鲜肉
小鲜肉 2021-01-31 10:33

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

public void setupTabLayout(TabLayout tabLayout) {
    tabLayout         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 11:29

    You can use the attribute android:layout of TabItem to set custom view. In custom view xml file, remember to set id of icon and text view to @android:id/icon and android:id="@android:id/text1", then the library will take care the rest.

    Here's an example:

    . custom_tab_item.xml

    
    
      
    
      
    
    
    

    . main.xml

    
    
      
    
      
    
    
    

    Hope this help.

提交回复
热议问题