1.在 build.gradle下添加
repositories {
...
maven { url "https://jitpack.io" }
}
2.添加依赖
dependencies {
compile 'com.github.DxTT:coolMenu:v1.1'
}
3.在XML你的布局中添加CoolMenuFrameLayout控件
<com.dxtt.coolmenu.CoolMenuFrameLayout
android:id="@+id/rl_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:num="four"/>
添加卡片的数量 上限是5张
app:num="five"
您可以在xml中设置标题图标或标题样式,如下所示:
app:titleSize =“@ dimen / cl_title_size”
app:titleColor =“@ color / colorPrimary”
app:titleIcon =“@ drawable / menu”
相关代码:
coolMenuFrameLayout = findViewById(R.id.rl_main);
String[] titles = {"星期一", "星期二", "星期三", "星期四","星期五"};
List<String> titleList = Arrays.asList(titles);
coolMenuFrameLayout.setTitles(titleList);
coolMenuFrameLayout.setMenuIcon(R.drawable.menu2);
fragments.add(new Fragment1());
fragments.add(new Fragment2());
fragments.add(new Fragment3());
fragments.add(new Fragment4());
fragments.add(new Fragment5());
FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
};
coolMenuFrameLayout.setAdapter(adapter);