android实现第一次打开应用的介绍页面

效果图

 

 

 

 添加依赖

    implementation 'com.github.AppIntro:AppIntro:6.2.0'
复制代码
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        maven {
            url "https://jitpack.io"
        }
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}
rootProject.name = "onbor"
include ':app'
复制代码

文件中加入上面加粗内容

 

 

 IntroActivity文件内容

复制代码
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;


import com.github.appintro.AppIntro;
import com.github.appintro.AppIntroPageTransformerType;



public class IntroActivity extends AppIntro {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setProgressIndicator();
            setNextArrowColor(Color.parseColor("#2196F3"));
            setColorDoneText(Color.parseColor("#2196F3"));
            setSkipButtonEnabled(false);
            setTransformer(AppIntroPageTransformerType.Fade.INSTANCE);
            addSlide(new PermissionActivity());
            addSlide(new WelcomeActivity());
    }


    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onDonePressed(Fragment currentFragment) {
        super.onDonePressed(currentFragment);
        finish();
        Intent intent = new Intent(IntroActivity.this, MainActivity.class);
        startActivity(intent);
    }

}
复制代码

addSlide(new WelcomeActivity());

这个class写起来和fragment一样,正常xml就可以

复制代码
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;


public class PermissionActivity extends Fragment {
    private View root;



    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (root == null) {
            root = inflater.inflate(R.layout.activity_permission, container, false);
        }
        return root;
    }

}
复制代码

manifest的声明给父亲就可以子class不要

复制代码
<activity
            android:name=".IntroActivity"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
复制代码

GitHub地址 下载前给star

posted @   Z_Chan  阅读(191)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示