ChromeLikeTabSwitcher
介绍:
Android类似于Android版Chrome上的tab效果。
运行效果:
使用说明:
依赖
dependencies {
compile 'com.github.michael-rapp:chrome-like-tab-switcher:0.1.0'
}
xml中定义TabSwitcher
<?xml version="1.0" encoding="utf-8"?>
<de.mrapp.android.tabswitcher.TabSwitcher
android:id="@+id/tab_switcher"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/tab_switcher_background_color"
custom:layoutPolicy="auto"
custom:tabIcon="@drawable/ic_file_outline_18dp"
custom:tabBackgroundColor="@color/tab_background_color"
custom:tabTitleTextColor="@color/tab_title_text_color"
custom:tabCloseButtonIcon="@ic_close_18dp"
custom:toolbarTitle="@string/tab_switcher_toolbar_title"
custom:toolbarMenu="@menu/tab_switcher_toolbar_menu"
custom:toolbarNavigationIcon="@drawable/ic_add_box_white_24dp"/>
或者在代码中定义
TabSwitcher tabSwitcher = new TabSwitcher(context);
tabSwitcher.setBackground(ContextCompat.getColor(context, R.color.tab_switcher_background_color);
tabSwitcher.setLayoutPolicy(LayoutPolicy.AUTO);
tabSwitcher.setTabIcon(R.drawable.ic_file_outline_18dp);
tabSwitcher.setTabBackgroundColor(ContextCompat.getColor(context, R.color.tab_background_color);
tabSwitcher.setTabTitleTextColor(ContextCompat.getColor(context, R.color.tab_title_text_color);
tabSwitcher.setTabCloseButtonIcon(R.drawable.ic_close_18dp);
tabSwitcher.setToolbarTitle(context.getString(R.string.tab_switcher_toolbar_title));
tabSwitcher.inflateToolbarMenu(R.menu.tab_switcher_toolbar_menu, null);
tabSwitcher.setToolbarNavigationIcon(R.drawable.ic_add_box_white_24dp, null);
向TabSwitcher中添加卡片
Tab tab = new Tab("Title");
tab.setCloseable(true);
tab.setIcon(R.drawable.ic_file_outline_18dp);
tab.setBackgroundColor(ContextCompat.getColor(context, R.color.tab_background_color));
tab.setTitleTextColor(ContextCompat.getColor(context, R.color.tab_title_text_color));
tab.setParameters(new Bundle());
tab.addCallback(new Tab.Callback() { /* ... */ });
tabSwitcher.addTab(tab);
已下载
0