Android: How can I change icons size in Action Bar Tabs?

五迷三道 提交于 2019-12-23 16:14:16

问题


I created an Action Bar Tabs activity for my project. I used 3 tabs and I added some icons. But the icons are shown in a small size, even if I downloaded them in 48dp.

My code is:

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

final private int[] tabIcons = {
        R.drawable.ic_photo_library,
        R.drawable.ic_chat,
        R.drawable.ic_people
};

private void setupTabsIcons() {

    tabLayout.getTabAt(0).setIcon(tabIcons[0]);
    tabLayout.getTabAt(1).setIcon(tabIcons[1]);
    tabLayout.getTabAt(2).setIcon(tabIcons[2]);

}

How could I change the size of the icons? I also have a FloatingActionButton with the same problem. The icon inside it is small.


回答1:


Just add Tab you self.

TabLayout layout = new TabLayout(TestActvt.this);
View view = getLayoutInflater().inflate(R.layout.custom,null);
view.findViewById(R.id.img).setImageResource(R.drawable.img);
TabLayout.Tab tab = layout.newTab().setCustomView(view);
layout.addTab(tab);

FloatingActionButton only has 2 size : mini or normal and Iamge in them has fixed size.



来源:https://stackoverflow.com/questions/34068329/android-how-can-i-change-icons-size-in-action-bar-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!