智能管家(一)

news/2024/7/7 11:46:52

#第一章:项目的准备
##一、项目的第一步
导入包

       compile 'com.android.support:design:24.2.1'

软件包分类:

       com.yijia.com.smartbutler.adapter
       com.yijia.com.smartbutler.application
       com.yijia.com.smartbutler.entity
       com.yijia.com.smartbutler.fragment
       com.yijia.com.smartbutler.service
       com.yijia.com.smartbutler.ui
       com.yijia.com.smartbutler.utils
       com.yijia.com.smartbutler.view
##二、主布局
    <?xml version="1.0" encoding="UTF-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.design.widget.TabLayout
            android:id="@+id/mTabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/colorAccent"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/colorAccent"
            app:tabTextColor="@android:color/white" />

        <android.support.v4.view.ViewPager
            android:id="@+id/mViewPager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

    </LinearLayout>
    //悬浮按钮
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_setting"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="15dp"
        android:layout_marginRight="15dp"
        android:src="@drawable/icon_setting" />

     </RelativeLayout>
##三、BaseActivity——Activity的基类
             显示返回键:
             getSupportActionBar().setDisplayHomeAsUpEnabled(true);


           //菜单栏操作
         @Override
         public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()){
            case android.R.id.home://系统自带的返回键点击退出程序
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
##四、MainActivity
###①初始化数据initData:添加标题和Fragment
    //初始化数据
    private void initData() {
        mTiltle = new ArrayList<String>();
        mTiltle.add("服务管家");
        mTiltle.add("微信精选");
        mTiltle.add("美女社区");
        mTiltle.add("个人中心");

        mFragment = new ArrayList<Fragment>();
        mFragment.add(new BulterFragment());
        mFragment.add(new WeChatFragment());
        mFragment.add(new GirlFragment());
        mFragment.add(new UserFragment());
    }
###②初始化initView:
 //初始化view
    private void initView() {
        mTabLayout = (TabLayout) findViewById(R.id.mTabLayout);
        mViewPager = (ViewPager) findViewById(R.id.mViewPager);

        //预加载
        mViewPager.setOffscreenPageLimit(mFragment.size());
    
        //设置适配器
        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            //选中的
            @Override
            public Fragment getItem(int position) {
                return mFragment.get(position);
            }

            //返回item的个数
            @Override
            public int getCount() {
                return mFragment.size();
            }

            //返回标题
            @Override
            public CharSequence getPageTitle(int position) {
                return mTiltle.get(position);
            }
        });
        mTabLayout.setupWithViewPager(mViewPager);
    }
###③隐藏悬浮按钮
      mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    fab_setting.setVisibility(View.GONE);
                } else {
                    fab_setting.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });



http://www.niftyadmin.cn/n/3649372.html

相关文章

V1.0博客搭建与开发的31天

博客搭建与开发时间线2020年01月02日&#xff1a; 微笑涛声博客1.0版本正式开始搭建&#xff0c;博客采用WordPressMySQLPHPNGINX搭建基本框架。主题为WordPress默认。一天内完成基本框架搭建。 2020年01月03日&#xff1a; 从华为云购买域名cztcms.cn(云服务器已有)。同时域名…

智能管家(二)——工具类封装与首页引导页开发

#智能管家 ##第二章&#xff1a;工具类封装与首页引导页开发##一、log类的封装public class L {//开关public static final boolean DEBUG true;//TAGpublic static final String TAG "SmartButler";//五个等级 DIWEpublic static void d(String text){if(DEBUG)…

Angular+SpringBoot前后端分离项目上传云服务器

一、前端&#xff08;客户端&#xff09;上传服务器 1、安装nginx&#xff0c;开启服务&#xff0c;查看状态 安装&#xff1a;yum install nginx开启服务&#xff1a;service nginx start 重启服务&#xff1a;service nginx restart2、打包Angular项目–控制台输入 打包命…

删除安装包 react包_如何包装在React中使用的Vanilla JavaScript软件包

删除安装包 react包介绍 (Introduction) Complex web projects often require the use of 3rd party widgets. But what if you’re using a framework and the widget is only available in pure JavaScript? 复杂的Web项目通常需要使用第三方控件。 但是&#xff0c;如果您…

CentOS 7下载及安装教程

▣ 博主主站地址&#xff1a;微笑涛声 【www.cztcms.cn】 操作系统基本上都有服务器版本&#xff0c;像Windows有Windows server版本。服务器版即为可以搭建各种开发环境的系统&#xff0c;运行非常稳定。本教程是CentOS 7在虚拟机(VMware Workstation Pro 15)的安装教程。由于…

PHP利用数据库生成API

第一步&#xff1a;首先利用HBuilder建立一个PHP项目&#xff1a; 新建一个php文件,与数据库建立连接: <?php $conmysql_connect("localhost","root","") or die(mysql_error); mysql_select_db("test");//test为表名 ?…

Xftp和Xshelll的安装—远程连接linux

什么是xftp和xshell呢&#xff0c;来看看百度词条的解释。 Xftp——是一个功能强大的SFTP、FTP 文件传输软件。使用了 Xftp 以后&#xff0c;MS Windows 用户能安全地在 UNIX/Linux 和 Windows PC 之间传输文件。 Xshell——是一个强大的安全终端模拟软件&#xff0c;它…

react-hooks_如何使用React Hooks构建React To-Do应用

react-hooks介绍 (Introduction) React is a front-end JavaScript library that can be used to create interactive user interfaces for your application. In this tutorial, you will create a to-do app that covers all four aspects of a CRUD: Create, Read, Update, …