短视频平台源码,开屏后的广告引导页

短视频平台源码,开屏后的广告引导页
1、打开Android Studio,新建一个项目StartDemo,新建一个activity页面,命名为StartActivity

StartActivity.java代码如下。

先判断是否第一次启动app,如果是,则进入引导页;如果不是,则直接进入首页。

public class StartActivity extends AppCompatActivity {
    
    
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        initView();
    }
 
    private void initView() {
    
    
        SharedPreferences sp=getSharedPreferences("name",MODE_PRIVATE);
        boolean is=sp.getBoolean("ok",true);
        if (is){
    
    
            SharedPreferences.Editor editor=sp.edit();
            editor.putBoolean("ok",false);
            editor.apply();
            startActivity(new Intent(StartActivity.this,IntroductoryActivity.class));
        }else {
    
    
            startActivity(new Intent(StartActivity.this,MainActivity.class));
        }
    }
}

2、在AndroidManifest.xml文件中,将启动页面设置为.StartActivity

<activity android:name=".StartActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
 
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

3、新建一个activity页面,命名为IntroducttoryActivity

在IntroducttoryActivity.xml中添加ViewPager,代码如下:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".IntroductoryActivity">
    <androidx.viewpager.widget.ViewPager
        android:id="@+id/introductory_viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
 
</LinearLayout>

以上就是短视频平台源码,开屏后的广告引导页, 更多内容欢迎关注之后的文章

猜你喜欢

转载自blog.csdn.net/yb1314111/article/details/125145698