AppIntro Quick Start for Android Framework

Use of AppIntro

  1. Dependencies for AppIntro (added to gradle dependencies):
repositories {
    maven { url "https://jitpack.io" }
}
dependencies {
    // AndroidX Capable version
    implementation 'com.github.AppIntro:AppIntro:6.1.0'
    
    // *** OR ***
    
    // Latest version compatible with the old Support Library
    implementation 'com.github.AppIntro:AppIntro:4.2.3'
}
  1. Create a class to use Activity to inherit AppIntro (or inherit AppIntro2, showing different slide effects), and rewrite the three methods onCreate(), onSkipPressed(), onDonePressed()
  2. Use the addSlide() method in onCreate to display the picture of the welcome interface
  3. Declare in the manifests list file
  4. As follows:

AppIntroActivity.java

package com.it.appintro;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import com.github.appintro.AppIntro;
import com.github.appintro.AppIntroFragment;

import org.jetbrains.annotations.Nullable;

public class AppIntroActivity extends AppIntro {
    
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);

        /*
        * AppIntroFragment.newInstance()有多个重载方法,这里使用的是AppIntroFragment.newInstance(CharSequence title,CharSequence
        *  description,int imageDrawable)
        *
        * */
        addSlide(AppIntroFragment.newInstance("Welcome!",
                "This is a demo example in java of AppIntro library, with a custom background on each slide!",
                R.drawable.img1));

        addSlide(AppIntroFragment.newInstance(
                "Clean App Intros",
                "This library offers developers the ability to add clean app intros at the start of their apps.",
                R.drawable.img2
        ));


    }


    @Override
    protected void onSkipPressed(@Nullable Fragment currentFragment) {
    
    
        super.onSkipPressed(currentFragment);
        //finish直接返回上一层
        finish();
    }

    @Override
    protected void onDonePressed(@Nullable Fragment currentFragment) {
    
    
        super.onDonePressed(currentFragment);
        //finish直接返回上一层
        finish();
    }
}

manifests清单文件

<activity android:name=".AppIntroActivity"
            android:label="AppIntroActivity"/>

The running effect is as follows:


insert image description here

​ There are two slides in total. There are jump buttons and return buttons in the lower left and lower right corners (corresponding to the onSkipPress method and onDonePress method respectively), which we cannot see due to the background color (both background color and button color can be set) , but clicking will still execute our pre-defined finish() method

important point:

  • You cannot use the setContentView() method in the onCreate method, AppIntro's superclass will handle it automatically
  • The onCreate() method has multiple overloaded methods, what we need to use is the onCreate method with only one Bundle parameter
  • It is not recommended to declare MyCustomAppIntro as your first activity unless you want MyCustomAppIntro to start every time your application starts. Ideally, the AppIntro activity should only be shown to the user once, and when done it should be hidden (flag can be used in SharedPreferences).

AppIntroFragment.newInstance () overload method learning

We know that the method call of addSlide needs to pass a Fragment parameter. We usually use AppIntroFragment.newInstance() to obtain objects of Fragment type. Obviously, AppIntroFragment.newInstance() uses a singleton pattern, and there are many It is an overloaded method, but it contains certain rules. The method with more parameters is compared with the method with fewer parameters. The method with more parameters will contain all the parameters in the method with lower parameters, so we only need to learn AppIntroFragment with the most parameters. The .newInstance() method can master most of the overloaded methods, and the form with the most parameters is:

addSlide(AppIntroFragment.newInstance(
    title = "The title of your slide",
    description = "A description that will be shown on the bottom",
    imageDrawable = R.drawable.the_central_icon,
    backgroundDrawable = R.drawable.the_background_image,
    titleColor = Color.YELLOW,
    descriptionColor = Color.RED,
    backgroundColor = Color.BLUE,
    titleTypefaceFontRes = R.font.opensans_regular,
    descriptionTypefaceFontRes = R.font.opensans_regular,
))

Let's modify the AppIntroActivity.java file:

package com.it.appintro;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import com.github.appintro.AppIntro;
import com.github.appintro.AppIntroFragment;

import org.jetbrains.annotations.Nullable;

public class AppIntroActivity extends AppIntro {
    
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);

        /*
        * AppIntroFragment.newInstance()有多个重载方法,这里使用的是AppIntroFragment.newInstance(CharSequence title,CharSequence
        *  description,int imageDrawable)
        *
        * */

        AppIntroFragment.newInstance();
        addSlide(AppIntroFragment.newInstance("Welcome!",
                "This is a demo example in java of AppIntro library, with a custom background on each slide!",
                R.drawable.img1, Color.GRAY,Color.RED,Color.BLACK)); //最后两个参数分别是标题的字体和讲述的字体,这里不再赘述

        addSlide(AppIntroFragment.newInstance(
                "Clean App Intros",
                "This library offers developers the ability to add clean app intros at the start of their apps.",
                R.drawable.img2,Color.GRAY,Color.RED,Color.BLACK
       ));


    }


    @Override
    protected void onSkipPressed(@Nullable Fragment currentFragment) {
    
    
        super.onSkipPressed(currentFragment);
        //finish直接返回上一层
        finish();
    }

    @Override
    protected void onDonePressed(@Nullable Fragment currentFragment) {
    
    
        super.onDonePressed(currentFragment);
        //finish直接返回上一层
        finish();
    }
}

The running effect is as follows:

insert image description here

insert image description here

Among them, AppIntroFragment.newInstance() also has a special overload method, which is to display a custom slideshow through a custom layout file. The code is as follows:

custom_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    android:background="@drawable/img1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:gravity="center"
        android:textColor="@color/black"
        android:layout_marginTop="20dp"
        android:text="这是自定义的"
        />
</LinearLayout>
//添加自定义的幻灯片
        addSlide(AppIntroCustomLayoutFragment.newInstance(R.layout.custom_activity));

Add slides through Slider

We can also set up the slide by manually setting the Slider without using the idea of ​​​​chain programming:

 //通过SliderPage来添加幻灯片
        SliderPage sliderPage = new SliderPage();
        sliderPage.setTitle("这是SliderPage");
        sliderPage.setDescription("这是自定义的SliderPage");
        sliderPage.setImageDrawable(R.drawable.img2);
        sliderPage.setBackgroundColor(Color.GRAY);
        sliderPage.setTitleColor(Color.BLUE);
        sliderPage.setDescriptionColor(Color.RED);
        addSlide(AppIntroFragment.newInstance(sliderPage));

Various configurations of AppIntro

After getting started with AppIntro, you need to use a variety of configurations to find your favorite style, such as fade-out, transition, etc. For specific configurations, please refer to the official document, and the official document address is attached here:

https://github.com/AppIntro/AppIntro

Finally, attach the AppIntro example in the official document (the specific notes in it have been Chinese, you can learn about the various configurations of AppIntro):

package com.github.appintro.example.ui.java;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.github.appintro.AppIntro;
import com.github.appintro.AppIntroFragment;
import com.github.appintro.AppIntroPageTransformerType;
import com.github.appintro.example.R;


public class JavaIntro extends AppIntro {
    
    

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);


        addSlide(AppIntroFragment.newInstance("Welcome!",
                "This is a demo example in java of AppIntro library, with a custom background on each slide!",
                R.drawable.ic_slide1));

        addSlide(AppIntroFragment.newInstance(
                "Clean App Intros",
                "This library offers developers the ability to add clean app intros at the start of their apps.",
                R.drawable.ic_slide2
        ));

        addSlide(AppIntroFragment.newInstance(
                "Simple, yet Customizable",
                "The library offers a lot of customization, while keeping it simple for those that like simple.",
                R.drawable.ic_slide3
        ));

        addSlide(AppIntroFragment.newInstance(
                "Explore",
                "Feel free to explore the rest of the library demo!",
                R.drawable.ic_slide4
        ));

        // 淡出过渡
        setTransformer(AppIntroPageTransformerType.Fade.INSTANCE);
        
        // 显示/隐藏状态栏
        showStatusBar(true);
        
        //加快或减慢滚动速度
        setScrollDurationFactor(2);
        
        //在两个幻灯片之间启用颜色“淡出”动画(确保幻灯片实现)
        setColorTransitionsEnabled(true);
        
        //防止后退按钮退出幻灯片
        setSystemBackButtonLocked(true);
        
        //激活向导模式(一些美学上的改变)
        setWizardMode(true);
        
        // 显示/隐藏跳过按钮
        setSkipButtonEnabled(true);
        
        //启用沉浸模式(无状态和导航条)
        setImmersiveMode();
        
        // 启用/禁用页面指示符
        setIndicatorEnabled(true);
        
        //展示/隐藏所有按钮
        setButtonsEnabled(true);
    }

    @Override
    protected void onSkipPressed(Fragment currentFragment) {
    
    
        super.onSkipPressed(currentFragment);
        finish();
    }

    @Override
    protected void onDonePressed(Fragment currentFragment) {
    
    
        super.onDonePressed(currentFragment);
        finish();
    }
}

Guess you like

Origin blog.csdn.net/weixin_45927121/article/details/120679073