是否可以在tablayout图标上设置URL图像?

时间:2017-12-26 16:42:11

标签: android kotlin

我在HomeActivity上有一个tablayout,它有一个静态图标。我想知道是否有可能以及如何制作,以便在此图标中显示用户的照片。它来自一个URL。

以下是活动代码:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setSupportActionBar(binding.toolbar)

    binding.search.setOnClickListener(object : View.OnClickListener {
        override fun onClick(p0: View?) {
            startActivity(Intent(this@HomeActivity, SearchActivity::class.java))
        }
    })

    binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_message_24dp))
    binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_history_24dp))
    binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_people_24dp))
    binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_settings_24dp))

    pagerAdapter = HomePagerAdapter(supportFragmentManager, binding.tabLayout.tabCount)

    binding.viewPager.adapter = pagerAdapter
    binding.viewPager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(binding.tabLayout))
    binding.tabLayout.setOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
        override fun onTabSelected(tab: TabLayout.Tab) {
            binding.viewPager.currentItem = tab.position
        }

        override fun onTabUnselected(tab: TabLayout.Tab) {}
        override fun onTabReselected(tab: TabLayout.Tab) {}
    })

    //registerMessagesObserver()
    if (savedInstanceState == null) {

    }
}

相关图标为binding.tabLayout.addTab (binding.tabLayout.newTab().SetIcon(R.drawable.ic_settings_24dp))

0 个答案:

没有答案