zoukankan      html  css  js  c++  java
  • tabLayout加viewPager的实现

    效果

    首先导入design;

    然后设置布局:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
      android:orientation="vertical"
        tools:context="com.example.mytablayoutdemo.MainActivity">
    <!--tabTextColor原本颜色,tabSelectedTextColor选中后颜色-->
        <android.support.design.widget.TabLayout
            android:id="@+id/mtab"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabTextColor="@color/colorPrimary"
            app:tabSelectedTextColor="@color/colorAccent"/>


        <android.support.v4.view.ViewPager
            android:id="@+id/mviewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </android.support.v4.view.ViewPager>
    </LinearLayout>

    然后设置fragment

    其次 adapter:

    package com.example.mytablayoutdemo;

    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;

    public class MyAdapter extends FragmentPagerAdapter {
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }
        @Override
        public Fragment getItem(int position) {
            return new BlankFragment();
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            String title=null;
            switch (position){
                case 0:
                    title="钢厂";
                    break;
                case 1:
                    title="丽丽";
                    break;
                case 2:
                    title="小夏";
                    break;
            }
            return title;
        }
    }
    最后activity

     搞定!练习知识点,仅供参考

  • 相关阅读:
    mysql GROUP_CONCAT 查询某个字段(查询结果默认逗号拼接)
    mysql中find_in_set的使用
    Libev源码分析07:Linux下的eventfd简介
    Libev源码分析06:异步信号同步化--sigwait、sigwaitinfo、sigtimedwait和signalfd
    Nova中的Hook机制
    Python深入:stevedore简介
    Libev源码分析05:Libev中的绝对时间定时器
    Python深入:setuptools简介
    Libev源码分析04:Libev中的相对时间定时器
    Libev源码分析02:Libev中的IO监视器
  • 原文地址:https://www.cnblogs.com/ll-ouyang/p/6420256.html
Copyright © 2011-2022 走看看