[英]How to place image icons in tab in android?
I need to implement the tab widget with icon in this screen shot.我需要在此屏幕截图中实现带有图标的选项卡小部件。
Can anyone please explain how it needs to be implemented using fragments.任何人都可以解释如何使用片段来实现它。 If we click the image icon it should display listview.如果我们单击图像图标,它应该显示列表视图。
Thanks.谢谢。
Use TabLayout
to do that.使用TabLayout
来做到这一点。
xml: xml:
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:minHeight="100dp"
app:tabGravity="fill"
app:tabMode="fixed"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
code:代码:
tabLayout.addTab(tabLayout.newTab().setIcon(...));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
switch (tabLayout.getSelectedTabPosition()) {
case 0:
//do what you want when tab 0 is selected
break;
case 1:
//do what you want when tab 1 is selected
break;
case 2:
//do what you want when tab 2 is selected
break;
default:
break;
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.