<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.myapplication.MainActivity">
<FrameLayout
android:id="@+id/full_video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"></FrameLayout>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
<ProgressBar
android:id="@+id/progress"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:visibility="gone"/>
</FrameLayout>
要加入FrameLayout 方便后面放大
bd =(ImageView) findViewById ( R.id.imageView6 );
bd.setOnClickListener ( new View.OnClickListener () {
@Override
public void onClick ( View v ) {
Intent intent =new Intent ( v.getContext (),baidu.class);
v.getContext ().startActivity ( intent );
}
} );
正常导入百度activity就可以了
public class baidu extends AppCompatActivity {
WebView webview;
WebSettings settings;
private View customView ;
protected FrameLayout fullVideo;
private ProgressBar progressBar;
@Override
protected void onCreate( Bundle savedInstanceState) {
super.onCreate ( savedInstanceState );
setContentView ( R.layout.baidu );
webview = (WebView) findViewById ( R.id.webView );
fullVideo =(FrameLayout) findViewById (R.id.full_video);
progressBar=findViewById(R.id.progress);
webview.loadUrl ( "file:///android_asset/demo.html" );
webview.setWebChromeClient ( new MyChrome() );
webview.setWebViewClient(new WebViewClient());
settings = webview.getSettings();
settings.getJavaScriptEnabled ();
}
所有东西都正常导入
加载setting
允许java script进行改变
载入 webviewclient
仿写 webchormClient(仿写里面的method 达到放大和缩小的效果)
public class MyChrome extends WebChromeClient {
MyChrome () {
// setRequestedOrientation ( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
//
}
@Override
public void onHideCustomView() {
//退出全屏
if (customView == null){
return;
}
//移除全屏视图并隐藏
((FrameLayout)getWindow().getDecorView()).removeView(customView);
customView = null;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
@Override
public void onShowCustomView(View view, CustomViewCallback callback){
customView = view;
fullVideo.setVisibility(View.VISIBLE);
fullVideo=((FrameLayout)getWindow().getDecorView());
fullVideo.addView(customView, new FrameLayout.LayoutParams(-1, -1));//设置大屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//设置横屏
}
在manifest的相关activity 加入这句话
android:configChanges = “orientation|screenSize” 用以解决bug