Describes how to add a video background to the interface found on the Internet, which mimics keep
1. First add the raw folder under the res folder and copy in the video you want to use
2. Add video_under the layout folderBackground.xmlLayout, add Videview control inside layout
3. Change AndroidManifest.xml Content removes Bar from the display of the video background page (the top one)
4.activity_Login.xmlAdd to video_Background.xmlReferences
5. Add source code to add video background to onCreate() method in corresponding class of video background page (login is LoginActivity)
Below is the code involved, remember to top it up if you like
Video_Background.xmlAdded VideoView
<!--LoginActivity in include Referenced Style-->
<!--The last four properties make the video full screen-->
<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"/>
<!--LoginActivity in include Referenced Style--> <!--The last four properties make the video full screen--> <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 Code that removes Bar from
!--Remove the title of the current page-->
<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>
!--Remove the title of the current page--> <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.xmlAdd to video_Background.xmlReferences
<include layout="@layout/video_background"/>
<include layout="@layout/video_background"/>
Code to add videos in onCreate() of LoginActivity
/Code for setting video background
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();
}
});
/Code for setting video background 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(); } });