首先写布局文件activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/video_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
></FrameLayout>
<Button
android:id="@+id/video_landport"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="全屏不显示该按扭,点击切换横屏"
android:gravity="center"
/>
<WebView
android:id="@+id/video_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
原理:实现全屏的时候把webview里的视频放到一个View(布局里的video_view控件)里面,然后把webview隐藏掉!这样就实现了全屏播放的!
现在具体来看看怎么实现的:
先放代码MainActivity.java:
public class MainActivity extends Activity {
private FrameLayout videoview;// 全屏时视频加载view
private Button videolandport;
private WebView videowebview;
private Boolean islandport = true;//true表示此时是竖屏,false表示此时横屏。
private View xCustomView;
private xWebChromeClient xwebchromeclient;
private String url = "http://look.appjx.cn/mobile_api.php?mod=news&id=12604";
private WebChromeClient.CustomViewCallback xCustomViewCallback;
@Override
protected v