没有合适的资源?快使用搜索试试~ 我知道了~
首页Android使用WebView实现全屏切换播放网页视频功能
资源详情
资源评论
资源推荐
Android使用使用WebView实现全屏切换播放网页视频功能实现全屏切换播放网页视频功能
主要介绍了Android使用WebView实现全屏切换播放网页视频功能,本文通过实例代码给大家介绍的非常详细,需要的朋
友可以参考下
首先写布局文件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 void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉应用标题
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
initwidget();
initListener();
videowebview.loadUrl(url);
}
private void initListener() {
// TODO Auto-generated method stub
videolandport.setOnClickListener(new Listener());
}
private void initwidget() {
// TODO Auto-generated method stub
videoview = (FrameLayout) findViewById(R.id.video_view);
videolandport = (Button) findViewById(R.id.video_landport);
videowebview = (WebView) findViewById(R.id.video_webview);
WebSettings ws = videowebview.getSettings();
/**
* setAllowFileAccess 启用或禁止WebView访问文件数据 setBlockNetworkImage 是否显示网络图像
* setBuiltInZoomControls 设置是否支持缩放 setCacheMode 设置缓冲的模式
* setDefaultFontSize 设置默认的字体大小 setDefaultTextEncodingName 设置在解码时使用的默认编码
* setFixedFontFamily 设置固定使用的字体 setJavaSciptEnabled 设置是否支持Javascript
* setLayoutAlgorithm 设置布局方式 setLightTouchEnabled 设置用鼠标激活被选项
* setSupportZoom 设置是否支持变焦
* */
ws.setBuiltInZoomControls(true);// 隐藏缩放按钮
ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);// 排版适应屏幕
ws.setUseWideViewPort(true);// 可任意比例缩放
ws.setLoadWithOverviewMode(true);// setUseWideViewPort方法设置webview推荐使用的窗口。setLoadWithOverviewMode方法是设置webview加载的页面的模式。
ws.setSavePassword(true);
ws.setSaveFormData(true);// 保存表单数据
weixin_38502915
- 粉丝: 5
- 资源: 914
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- ExcelVBA中的Range和Cells用法说明.pdf
- 基于单片机的电梯控制模型设计.doc
- 主成分分析和因子分析.pptx
- 共享笔记服务系统论文.doc
- 基于数据治理体系的数据中台实践分享.pptx
- 变压器的铭牌和额定值.pptx
- 计算机网络课程设计报告--用winsock设计Ping应用程序.doc
- 高电压技术课件:第03章 液体和固体介质的电气特性.pdf
- Oracle商务智能精华介绍.pptx
- 基于单片机的输液滴速控制系统设计文档.doc
- dw考试题 5套.pdf
- 学生档案管理系统详细设计说明书.doc
- 操作系统PPT课件.pptx
- 智慧路边停车管理系统方案.pptx
- 【企业内控系列】企业内部控制之人力资源管理控制(17页).doc
- 温度传感器分类与特点.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0