• 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

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

  • 相关阅读:
    spring复杂数据类型传递
    spring表单—乱码解决方案
    spring重定向与转发
    线程在WPF中的使用
    xheditor编辑器上传截图图片抓取远程图片代码
    js window.open()弹出窗口参数说明及居中设置
    INFORMATION_SCHEMA.COLUMNS 查询表字段语句
    SQL 使用Cursor(游标)遍历结果集
    js禁止浏览器滚屏方法
    基础-ADO插入数据后返回自增ID @@IDENTITY
  • 原文地址:https://www.cnblogs.com/ll-ouyang/p/6420256.html
Copyright © 2020-2023  润新知