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
分类:
Android开发
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了