介绍一下从网上找到的在界面中添加视频背景的方法,效果仿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"/>
<!--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 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"/>
<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();
}
});
/设置视频背景的代码代码
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();
}
});
效果如下: