首先写出tablayout的控件
<android.support.design.widget.TabLayout
</android.support.design.widget.TabLayout>
下方ViewPager
<android.support.v4.view.ViewPager
</android.support.v4.view.ViewPager>
然后写ViewPager的适配器 需要添加一个getPageTitle来返回 可以定义一个数组
private String[] title={"头条","两条"};
public MyFrem(FragmentManager fm, ArrayList<Fragment> list) {
super(fm);
this.list = list;
}
@Override
public Fragment getItem(int position) {
return list.get(position);
}
@Override
public int getCount() {
return list.size();
}
@Override
public CharSequence getPageTitle(int position) {
return title[position];
}
在.java里面里面需要有一行必要的代码 绑定下方的ViewPager
tabLayout.setupWithViewPager(pager);
Drawerlayout的监听
layout.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(@NonNull View view, float v) {
}
@Override
public void onDrawerOpened(@NonNull View view) {
}
@Override
public void onDrawerClosed(@NonNull View view) {
Toast.makeText(ZYActivity.this,"谈出来",Toast.LENGTH_SHORT).show();
}
@Override
public void onDrawerStateChanged(int i) {
}
});