您的位置:首页 > 移动开发

简单实现android的WebView

2013-06-27 19:51 471 查看
废话不多说,直接上代码

首先布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@color/bg_webview"

android:orientation="vertical" >

<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="45dp"

android:background="@drawable/bg_home_title" >

<TextView

android:id="@+id/wall_title"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:text="帮助"

android:textColor="@color/white"

android:textSize="21sp" />

</RelativeLayout>

<WebView

android:id="@+id/setting_help_content"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_marginLeft="15dp"

android:layout_marginRight="15dp"

android:background="@color/bg_webview"

android:cacheColorHint="#00000000"

android:fadingEdge="none"

android:scrollbars="none" />

</LinearLayout>

然后主界面Activity:

package com.suning.mobile.epa.activity.help;

import android.os.Bundle;

import android.webkit.WebView;

import android.webkit.WebSettings.LayoutAlgorithm;

import android.webkit.WebSettings.RenderPriority;

import com.suning.mobile.epa.R;

import com.suning.mobile.epa.RootActivity;

/**

* 设置界面中的帮助界面

*

* @Title:

* @Description:

* @Author:86042765 shenxiaobing

* @Since:2013-6-27

* @Version:

*/

public class SettingHelpActivity extends RootActivity

{

private static final String SETTING_HELP_URL = "file:///android_asset/setting_help.html";

//这个是android工程中assets中的一个html文本。。该文本为:setting_help.html

private WebView mSettingHelpContent;

@Override

protected void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_setting_help);

mSettingHelpContent = (WebView) findViewById(R.id.setting_help_content);

// 设置webview 自适应屏幕

mSettingHelpContent.getSettings().setLayoutAlgorithm(

LayoutAlgorithm.SINGLE_COLUMN);

// webview 背景

mSettingHelpContent.setBackgroundColor(getResources().getColor(

R.color.bg_webview));

// 优先加载文字

mSettingHelpContent.getSettings()

.setRenderPriority(RenderPriority.HIGH);

mSettingHelpContent.loadUrl(SETTING_HELP_URL); //实现加载。

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: