来自服务器的android

来自服务器的android

本文介绍了来自服务器的android TabLayout设置图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 Picasso 库在 TabLayout 上从服务器上设置图标吗?

can i set icon from server on 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));

but i don't want icon from resId i want to set icon from my server tabLayout.addTab(tabLayout.newTab().setIcon(path ));

还是我必须使用其他类解决此问题?

or must i use another class for this issue ?

推荐答案

您可以添加带有自定义视图的选项卡项.查看.

You can add a tab item with a custom view. Look at this.

请参见以下示例:

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;
}

现在,您可以添加带有自定义视图的标签项.

Now, you can add tab items with a custom view.

tabLayout.addTab(tabLayout.newTab().setCustomView(createTabItemView("image URL")));

这篇关于来自服务器的android TabLayout设置图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:49