java h5页面嵌入移动端_小视频源码,Android内嵌H5页面展示

本文介绍了如何在Android应用中嵌入H5页面,以展示小视频源码。主要使用WebView控件,并通过设置WebViewClient和WebChromeClient来处理页面加载和交互。代码示例包括加载URL、监听加载进度和修改页面标题。
摘要由CSDN通过智能技术生成

小视频源码,Android内嵌H5页面展示的相关代码

主要是使用WebView控件

//布局

xmlns:app="

xmlns:tools="

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".WebViewActivity">

android:id="@+id/webview"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

//使用

final WebView webView = findViewById(R.id.webview);

webView.setWebViewClient(new WebViewClient(){

@Override

public boolean shouldOverrideUrlLoading(WebView view, String url) { //设置在当前页面加载h5页面,不启动浏览器

view.loadUrl(url);

return true;

}

});

chromeClient = new WebChromeClient(){

@Override

public void onProgressChanged(WebView view, int newProgress) { //加载进度

super.onProgressChanged(view, newProgress);

Log.e("MainActivity", "progress:::::"+newProgress);

}

@Override

public void onReceivedTitle(WebView view, String title) { //标题修改

super.onReceivedTitle(view, title);

Log.e("MainActivity", "title:::::"+title);

}

};

webView.setWebChromeClient(chromeClient);

webView.loadUrl(");

findViewById(R.id.click).setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

chromeClient.onReceivedTitle(webView,"title");//修改标题

}

});

以上就是

小视频源码,Android内嵌H5页面展示的相关代码, 更多内容欢迎关注之后的文章

H5做的商城客户端,效果和android原生客户端没多大区别,现在h5是越来越火了, android的小伙伴们又遇到一个新的挑战了。本项目只能学习一下WebViewActivity使用, 但是由于js看不到,所以补发看到里面的方法, 主要代码: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_webview); ButterKnife.bind(this); String url = getIntent().getStringExtra(EXTRA_URL); mWebView.setWebViewClient(new WebViewClient()); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); mWebView.loadUrl(url); setupActionBar(url); } 还有就是CustomTabActivityHelper类封装了 /** * Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView * * @param activity The host activity * @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available * @param uri the Uri to be opened * @param fallback a CustomTabFallback to be used if Custom Tabs is not available */ public static void openCustomTab(Activity activity, CustomTabsIntent customTabsIntent, Uri uri, CustomTabFallback fallback) { String packageName = CustomTabsHelper.getPackageNameToUse(activity); //If we cant find a package name, it means there's no browser that supports //Chrome Custom Tabs installed. So, we fallback to the webview if (packageName == null) { if (fallback != null) { fallback.openUri(activity, uri); } } else { customTabsIntent.intent.setPackage(packageName); customTabsIntent.launchUrl(activity, uri); } } /** * Unbinds the Activity from the Custom Tabs Service * @param activity the activity that is connected to the service */ public void unbindCustomTabsService(Activity activity) { if (mConnection == null) return; activity.unbindService(mConnection); mClient = null; mCustomTabsSession = null; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值