Android登錄註冊界面添加視頻背景方法(簡單版)

介紹一下從網上找到的在界面中添加視頻背景的方法,效果仿keep

1.首先在res文件夾下添加raw文件夾並將要用的視頻複製進去

2.在layout文件夾下添加video_background.xml佈局,佈局內添加Videview控件

3.更改AndroidManifest.xml內容去掉展示視頻背景頁面的Bar(最上方上那一塊)

4.activity_login.xml中添加對video_background.xml的引用

5.視頻背景的頁面的對應類(登陸就是LoginActivity)中onCreate()方法中加入添加視頻背景的源碼

下方是涉及到的代碼,喜歡的話記得頂一下吐舌頭


video_background.xml添加的VideoView

    <!--LoginActivity中include引用的樣式-->
    <!--最後四個屬性使視頻全屏-->
    <VideoView
        android:id="@+id/videoview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:foregroundGravity="center"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"/>


AndroidManifest.xml中去掉Bar的代碼

	!--去掉當前頁面的標題-->
        <activity android:name=".LoginActivity"

            android:theme="@style/Theme.AppCompat.NoActionBar">

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


activity_login.xml中添加對video_background.xml的引用

<include layout="@layout/video_background"/>


LoginActivity的onCreate()中添加視頻的代碼

	/設置視頻背景的代碼代碼
        final VideoView videoview=(VideoView)findViewById(R.id.videoview);
        final String videopath = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.vdeo).toString();
        videoview.setVideoPath(videopath);
        videoview.start();
        videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                mediaPlayer.start();
                mediaPlayer.setLooping(true);
            }
        });
        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
            @Override
            public void onCompletion(MediaPlayer mediaPlayer) {
                videoview.setVideoPath(videopath);
                videoview.start();
            }
        });

效果如下:



極簡版源碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章