TabLayout、ViewPager、NavigationView
package com.example.carson_ho.toptabbar;import android.os.Bundle;import android.support.design.widget.TabLayout;import android.support.v4.view.ViewPager;import android.support.v7.app.AppCompatActivity;public class MainActivity extends AppCompatActivity { private TabLayout mTabLayout; private ViewPager mViewPager; private MyFragmentPagerAdapter myFragmentPagerAdapter; private TabLayout.Tab one; private TabLayout.Tab two; private TabLayout.Tab three; private TabLayout.Tab four; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().hide(); setContentView(R.layout.activity_main); //初始化视图 initViews(); } private void initViews() { mViewPager= (ViewPager) findViewById(R.id.viewPager); myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(myFragmentPagerAdapter); mTabLayout = (TabLayout) findViewById(R.id.tabLayout); mTabLayout.setupWithViewPager(mViewPager); one = mTabLayout.getTabAt(0); two = mTabLayout.getTabAt(1); three = mTabLayout.getTabAt(2); four = mTabLayout.getTabAt(3); one.setIcon(R.mipmap.ic_launcher); two.setIcon(R.mipmap.ic_launcher); three.setIcon(R.mipmap.ic_launcher); four.setIcon(R.mipmap.ic_launcher); }}
评论