【发布时间】:2018-11-12 17:13:15
【问题描述】:
在我的项目中我有这个代码
tabLayout.getTabAt(0).setIcon(R.drawable.location);
tabLayout.getTabAt(1).setIcon(R.drawable.list);
这使得图标出现在文本的顶部,我需要它们在左边
我试过了:
ConstraintLayout cl = (ConstraintLayout) LayoutInflater.from(this).inflate(R.layout.tab, null);
TextView tab = cl.findViewById(R.id.textViewTab);
tab.setText("Ver mapa");
tab.setTextColor(getResources().getColor(R.color.tabActive));
tab.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.location, 0, 0, 0);
tabLayout.getTabAt(0).setCustomView(tab);
tab.setText("Ver lista");
tab.setTextColor(getResources().getColor(R.color.tabInactive));
tab.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.list, 0, 0, 0);
tabLayout.getTabAt(1).setCustomView(tab);
但我得到了这个结果
漂亮,但不是我想要的
【问题讨论】:
-
为什么你不通过 xml 这样做
-
这会有什么不同吗?