淘先锋技术网

首页 1 2 3 4 5 6 7

本文将带你了解Android应用开发之使用Android Crosswalk播放video标签全屏问题解决,希望本文对大家学Android有所帮助

1,通过配置XWalkView的全屏事件进行处理拦截点

Java代码    webView.setUIClient(new InjectedXWalkUIClient(webView, mJsCallJava, listener));    public class InjectedXWalkUIClient extends XWalkUIClient {  ......  @Override      public void onFullscreenToggled(XWalkView view, boolean enterFullscreen) {          super.onFullscreenToggled(view, enterFullscreen);          Log.e(TAG, "onFullscreenToggled: "+enterFullscreen);  // 注册的回调监听接口          if (this.listener != null) {              this.listener.onFullscreenToggled(view,enterFullscreen);          }      }  ......  }  webView.setUIClient(new   InjectedXWalkUIClient(webView, mJsCallJava, listener));

public class InjectedXWalkUIClient extends XWalkUIClient {

......

@Override

public void   onFullscreenToggled(XWalkView view, boolean enterFullscreen) {

super.onFullscreenToggled(view, enterFullscreen);

Log.e(TAG,   "onFullscreenToggled: "+enterFullscreen);

// 注册的回调监听接口

if (this.listener != null)   {

this.listener.onFullscreenToggled(view,enterFullscreen);

}

}

......

}

2,在listener的onFullscreenToggled中进行处理,核心代码

Java代码    this.isFullScreen = enterFullscreen;  if (enterFullscreen) {      // 设置标题栏是否可见      this.common_top_layout.setVisibility(GONE);      // 横屏      this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);      // 全屏设置      WindowManager.LayoutParams attrs = getWindow().getAttributes();      attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;      this.getWindow().setAttributes(attrs);  } else {      // 设置标题栏可见      this.common_top_layout.setVisibility(View.VISIBLE);      // 竖屏      this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);      // 取消全屏      WindowManager.LayoutParams attrs = getWindow().getAttributes();      attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;      this.getWindow().setAttributes(attrs);  }  this.isFullScreen   = enterFullscreen;

if (enterFullscreen) {

// 设置标题栏是否可见

this.common_top_layout.setVisibility(GONE);

// 横屏

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

// 全屏设置

WindowManager.LayoutParams attrs   = getWindow().getAttributes();

attrs.flags |=   WindowManager.LayoutParams.FLAG_FULLSCREEN;

this.getWindow().setAttributes(attrs);

} else {

// 设置标题栏可见

this.common_top_layout.setVisibility(View.VISIBLE);

// 竖屏

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

// 取消全屏

WindowManager.LayoutParams attrs   = getWindow().getAttributes();

attrs.flags &=   ~WindowManager.LayoutParams.FLAG_FULLSCREEN;

this.getWindow().setAttributes(attrs);

}

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!