Changing TabLayout icons on left, top, right or bottom in com.android.support:design:23.1.0

后端 未结 4 1872
走了就别回头了
走了就别回头了 2020-12-23 15:06

I\'m pretty new to android development. So bear with me.

I\'ve been trying to align the icon and text in same line in com.android.support:design:23.1.0

4条回答
  •  抹茶落季
    2020-12-23 15:11

    Thank you Atu for this good tip!

    In my case, I have to add a linear layout to center tablayout title. I have also added some space characters to get margin between the icon and the text.

    custom_tab.xml:

    
    
        
    
    

    Initialization code:

    LinearLayout tabLinearLayout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
    TextView tabContent = (TextView) tabLinearLayout.findViewById(R.id.tabContent);
    tabContent.setText("  "+getApplicationContext().getResources().getString(tabTitles[i]));
    tabContent.setCompoundDrawablesWithIntrinsicBounds(tabIcons[i], 0, 0, 0);
    mTabLayout.getTabAt(i).setCustomView(tabContent);
    

提交回复
热议问题