android TabLayout 从服务器设置图标

2023-12-30

我可以从服务器上设置图标吗TabLayout using Picasso library

private string path = "192.168.0.102/project/a.png";

TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.aaa));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.bbbb));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.ccc));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.eee));

但我不想要 resId 中的图标 我想从我的服务器设置图标tabLayout.addTab(tabLayout.newTab().setIcon(path ));

或者我必须使用另一个类来解决这个问题?


您可以添加具有自定义视图的选项卡项目。看着this https://developer.android.com/reference/android/support/design/widget/TabLayout.Tab.html#setCustomView(android.view.View).

请参见以下示例:

private View createTabItemView(String imgUri) {
    ImageView imageView = new ImageView(this);
    TabLayout.LayoutParams params = new TabLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    imageView.setLayoutParams(params);
    Picasso.get.load(imgUri).into(imageView);
    return imageView;
}

现在,您可以使用自定义视图添加选项卡项目。

tabLayout.addTab(tabLayout.newTab().setCustomView(createTabItemView("image URL")));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android TabLayout 从服务器设置图标 的相关文章

随机推荐