TabLayout template usage: tablayout Template

Source: Internet
Author: User

TabLayout template usage: tablayout Template

Navigation bar:

compile 'com.android.support:design:26.0.0-alpha1'
TabLayout and ViewPager are used in combination:
List
 
  
TitleList = new ArrayList <> (); titleList. add ("Introduction"); titleList. add ("comment"); List
  
   
FragmentList = new ArrayList <> (); DescriptionFragment descriptionFragment = new DescriptionFragment (); fragmentList. add (descriptionFragment); fragmentList. add (new ValuationFragment (); MovieDetailVPAdapter movieDetailVPAdapter = new MovieDetailVPAdapter (getSupportFragmentManager (), titleList, fragmentList); movieJumpDetailViewpager. setAdapter (movieDetailVPAdapter); movieJumpDetailViewpager. setOffscreenPageLimit (2); movieJumpDetailTablayout. setupWithViewPager (movieJumpDetailViewpager); // combined with ViewPagermovieJumpDetailTablayout. setSelectedTabIndicatorColor (mainColor); movieJumpDetailTablayout. setTabTextColors (Color.
   WHITE, MainColor); movieJumpDetailTablayout. setBackgroundColor (Color.
   Argb(50,248,248,255 ));
  
 
ViewPager adapter:
package com.bwie.dongchangqi.personaltailor.Adapters;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentPagerAdapter;import java.util.List;/** * Created by Administrator on 2017/12/18 0018. */public class MovieDetailVPAdapter extends FragmentPagerAdapter{    private List
 
   titleList;    private List
  
    fragmentList;    public MovieDetailVPAdapter(FragmentManager fm,List
   
     titleList,List
    
      fragmentList) {        super(fm);        this.titleList = titleList;        this.fragmentList = fragmentList;    }    @Override    public Fragment getItem(int position) {        return fragmentList.get(position);    }    @Override    public int getCount() {        if(fragmentList==null||fragmentList.size()==0){            return 0;        }        return fragmentList.size();    }    @Override    public CharSequence getPageTitle(int position) {        return titleList.get(position);    }}
    
   
  
 
Layout:
xmlns:app="https://schemas.android.com/apk/res-auto"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.