How to increase the text size of a WebView?

6

My app reads from RSS. but what bothers me is the letter that is small, I want to leave it a little bigger than to be visually "right" by default. It is like this:

ButIwanttomakeitbiggertogetbetterreadingoftheuser.Forexample:

Code:

DetailFragment.java

package com.rs.player;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.rs.player.parser.RSSFeed;

public class DetailFragment extends Fragment {

    private int fPos;
    RSSFeed fFeed;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fFeed = (RSSFeed)getArguments().getSerializable("feed");
        fPos = getArguments().getInt("pos");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.detail_fragment, container, false);
        // Initializr views
        TextView title = (TextView)view.findViewById(R.id.title);
        WebView desc = (WebView)view.findViewById(R.id.desc);
        // Enable the vertical fading edge (by default it is disabled)
        // Set webview properties
        WebSettings ws = desc.getSettings();
        ws.setLightTouchEnabled(false);
        ws.setPluginState(PluginState.ON);
        ws.setJavaScriptEnabled(true);
        ws.setLoadWithOverviewMode(true);
        ws.setUseWideViewPort(true);
        ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
        ws.setBuiltInZoomControls(true);
        ws.setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
        // Set the views
        title.setText(fFeed.getItem(fPos).getTitle());
        desc.loadDataWithBaseURL("http://www.androidcentral.com/", fFeed.getItem(fPos)
                .getDescription(), "text/html", "UTF-8", null);
        return view;
    }
}

detail_fragment.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="5dp"
    android:paddingRight="5dp" >

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:text="@string/title"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textStyle="bold" />

            <WebView
                android:id="@+id/desc"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"

                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/title"
                android:scrollbarStyle="insideOverlay"
                android:text="@string/desc" />

</RelativeLayout>
    
asked by anonymous 01.12.2014 / 00:54

1 answer

1

You can use WebSettings to assign a text size to webView with setDefaultFontSize .

WebSettings wSettings = webView.getSettings();

/* setDefaultFontSize(int size); */
wSettings.setDefaultFontSize(18);
    
22.02.2015 / 20:56