-
- 在buil.gradler 的 dependencies 写入: compile'com.android.support:design:23.3.0'
- 在布局上写如: xmlns:app="http://schemas.android.com/apk/res-a"uto
-
//layout布局
<android.support.design.widget.TabLayoutandroid :layout_width= "match_parent"android :layout_weight= "1"android :layout_height= "40dp"app :tabMode= "scrollable"android :id= "@+id/tab"app :tabSelectedTextColor="@android:color/holo_red_light"></ android.support.design.widget.TabLayout>
//找到控件后
private static final String[] title = new String[]{ "娱乐" , "热点 " , " 科技 ", " 社会 ", "汽车 " , " 体育 ", " 推荐", " 财经" };
for (int i=0 ;i< title. length;i++){tab .addTab( tab.newTab().setText( title[i]));}
vp.setOnPageChangeListener( newTabLayout.TabLayoutOnPageChangeListener( tab ));//vp.addOnPageChangeListener(newTabLayout.TabLayoutOnPageChangeListener(tab));tab .setOnTabSelectedListener( newTabLayout.OnTabSelectedListener() {@Overridepublic void onTabSelected(TabLayout.Tab tab) {vp.setCurrentItem(tab.getPosition());}
@Overridepublic void onTabUnselected(TabLayout.Tab tab) {
}@Overridepublic void onTabReselected(TabLayout.Tab tab) {
}});

被折叠的 条评论
为什么被折叠?



