【问题标题】:How do I change the default tabicon position?如何更改默认的 tabicon 位置?
【发布时间】:2018-04-28 19:19:46
【问题描述】:

我添加了片段标题和图标,如下所示。默认情况下,选项卡图标位于上部。我想将这些图标保留在左侧。是否可以更改以下结构中的位置还是需要自定义代码?

    // Add Fragments to adapter one by one
    adapter.addFragment(new Home_Screen(), "Home");
    adapter.addFragment(new YebformCover(), "Yeb");
    adapter.addFragment(new ServiceCover(), "Service");
    adapter.addFragment(new FeaturedCover(), "Feature");
    viewPager.setAdapter(adapter);

    TabLayout tabLayout = findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.getTabAt(1).setIcon(R.drawable.ic_action_home);
    tabLayout.getTabAt(2).setIcon(R.drawable.ic_action_school);
    tabLayout.getTabAt(3).setIcon(R.drawable.ic_action_development);
    tabLayout.getTabAt(4).setIcon(R.drawable.ic_action_plan);

【问题讨论】:

    标签: android android-fragments android-tablayout


    【解决方案1】:

    您需要将 customView 设置为标签

    查看setCustomView(View),您需要将其应用于标签。

    创建自定义布局文件,使用LayoutInflater 扩展布局并将其设置为选项卡 -

    TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
    tabOne.setText("Tab 1");
    tabOne.setCompoundDrawablesWithIntrinsicBounds(R.drawable.your_icon, 0, 0, 0);
    // Set layout to first tab
    tabLayout.getTabAt(0).setCustomView(tabOne);
    

    【讨论】:

      猜你喜欢
      • 2014-12-18
      • 2015-09-07
      • 1970-01-01
      • 2021-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多