How to increase the text size of a Webview?

Asked

Viewed 505 times

6

My app reads RSS feeds. but what bothers me is the letter that is small, I want to leave a little bigger that is visually "right" in a standard way. It’s like this: inserir a descrição da imagem aqui

But I want to make it bigger to better read the user. For example: inserir a descrição da imagem aqui

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>
  • Already tried something like this: Websettings Settings = mWebView.getSettings(); Settings.setTextZoom(20);

  • did not help :/

  • Try to force directly into html: String text = "<html><style type="text/css">p{text-align:Justify;font-size:80%;}</style></head><body>"+"<p>"+CONTENTS+"</p>"+"</body></html>"; mWebView.loadData(text, "text/html", "utf-8");

  • In your xml vc did not specify the size of the text, for example: android:textSize="18sp"

1 answer

1

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

WebSettings wSettings = webView.getSettings();

/* setDefaultFontSize(int size); */
wSettings.setDefaultFontSize(18);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.