Android实现WebView加载网页及网页美化(简易新闻 四)

Android实现WebView加载网页及网页美化(简易新闻 四)

关于之前的功能实现可以从制作简易新闻App导航篇中查看

主要使用WebView显示网页,使用JavaScript去除顶部广告,使用Toolbar实现导航栏样式
最终效果如下:
在这里插入图片描述
接上一篇博客(连接数据库,实现下拉刷新(简易新闻 三)),先看一下Git动图

在这里插入图片描述
通过图片可以看到整个新闻网页分为三部分,分别是顶部Toolbar,WebView,Toolbar,具体实现方法如下。

第一步新建一个Empty Activity

新建一个WebActivity活动,修改activity_web.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context=".WebActivity">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_webview"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:background="@color/colorhuise"
            app:titleTextColor="@color/black"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <WebView
                android:id="@+id/webView"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1">

            </WebView>
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_webcomment"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:background="#ffffff"
                app:titleTextColor="@color/black"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:elevation="8dp"/>
        </LinearLayout>
    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

第二步添加color属性值

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent"
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雪の星空朝酱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值