Align Icons in Tab Layout To The Left

后端 未结 6 1480
被撕碎了的回忆
被撕碎了的回忆 2020-12-18 00:44

Hello I have created a tab layout in my activity. This is the main .xml file:




        
6条回答
  •  孤城傲影
    2020-12-18 01:31

    The answer given by @Tjerkw is ok just that it doesn't loop through the entire tab. I guess the right solution should be this

    for (int i = 0; i < tabLayout.getTabCount(); i++ ) {
         yourlinearlayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.title_text, null);
         tab_text = (TextView) yourlinearlayout.findViewById(R.id.tabContent);
                tab_text.setText("  " + tab_titles[i]);
         tab_text.setCompoundDrawablesWithIntrinsicBounds(tabicons[i], 0, 0, 0);
            tabLayout.getTabAt(i).setCustomView(tab_text);}
    

    and the layout resource .xml representing R.layout.title_text will be

    
    
    

    finally, the tabicons[i] and tab tab_titles[i] are just String arrays containing their respective contents. I know this question's old but i recently faced this and i'm sure someone else might still need this

提交回复
热议问题