WebView加载页面
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WebView加载页面相关的知识,希望对你有一定的参考价值。
<RelativeLayout 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=".InfoActivity" >
<WebView
android:id="@+id/wv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/info_share"
android:layout_alignParentTop="true" />
<Button
android:id="@+id/info_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="分享"
android:textSize="30sp" />
</RelativeLayout>
package com.bwie.jinritoutiao;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.UMQQSsoHandler;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
public class InfoActivity extends Activity {
UMSocialService mControllerShare;
Context mContext;
private String str_url;
private WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);
Intent intent=getIntent();
str_url = intent.getStringExtra("url");
mContext = this;
Button share=(Button) findViewById(R.id.info_share);
wv = (WebView) findViewById(R.id.wv);
WebSettings settings = wv.getSettings();// 获得websetting,设置一些参数
settings.setDefaultTextEncodingName("utf-8");// 设置编码,解决乱码
wv.loadUrl(str_url);// 加载html
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
wv.loadUrl(url);
return true;
}
});
mControllerShare = UMServiceFactory.getUMSocialService("com.umeng.share");
mControllerShare.setShareContent("今日头条");
// 设置分享图片, 参数2为图片的url地址
// mControllerShare.getConfig().removePlatform( SHARE_MEDIA.RENREN, SHARE_MEDIA.DOUBAN);
share.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
mControllerShare.setShareMedia(new UMImage(mContext, str_url));
// 是否只有已登录用户才能打开分享选择页
mControllerShare.openShare(InfoActivity.this, false);
}
});
//参数1为当前Activity, 参数2为开发者在QQ互联申请的APP ID,参数3为开发者在QQ互联申请的APP kEY.
UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(this, "100424468",
"56e8bed6e0f55aef5b001d18");
qqSsoHandler.addToSocialSDK();
//参数1为当前Activity, 参数2为开发者在QQ互联申请的APP ID,参数3为开发者在QQ互联申请的APP kEY.
QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(this, "100424468",
"56e8bed6e0f55aef5b001d18");
qZoneSsoHandler.addToSocialSDK();
}
}
以上是关于WebView加载页面的主要内容,如果未能解决你的问题,请参考以下文章