0

I have the following code (quite simple):

WebSettings webSettings = webView.getSettings();
webSettings.setTextZoom(110);

While running on Android 4.0, all is right. However, both Android 2.2 and Android 2.3.3 throw a "no such method" excepcion when trying to run setTextZoom (the same happens with getTextZoom). I know the previous setTextSize method is now deprecated but I found no info about whether setTextZoom existed back then. I know that my minSdkVersion is 8 and my target is 9 and Eclipse doesn't complain about setTextZoom.

While I could use setTextSize (now deprecated) I find NORMAL size too small and LARGE too big.

Any help is appreciated, thanks for your time!

francgo
  • 23
  • 5

1 Answers1

1

This should be supporting new and older APIs.

@SuppressWarnings("deprecation")
    @SuppressLint("NewApi")
    protected void updateTextSize(WebSettings settings) {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            settings.setTextZoom(some_value);
        } else {
            settings.setTextSize(TextSize.????);
        }
    }

EDIT Considering that your real problem is not accessing deprecated APIs, but rather the font size, I believe below is the answer you need:

protected void updateTextSize(WebSettings settings, int fontSize) {
        if(fontSize > 1 && fontSize < 72) {
            // there's no point setting a different value considering outside values will be pinned 
            settings.setDefaultFontSize(fontSize);
        }
    }
gunar
  • 14,660
  • 7
  • 56
  • 87
  • Thanks! I do know now that setTextZoom was introduced in API 14 so no wonder it wasn't working. I'm still looking for a way to have text inbetween NORMAL and LARGE in older APIs. – francgo Jun 07 '13 at 13:03
  • Not really, I appreciate your help but what I intend to do is to increase/decrease textSize in a WebView for Android 2.3 with more accuracy than setTextSize allows for. – francgo Jun 07 '13 at 15:02
  • Then why weren't you concise in what is your real problem when you posted the question? I'll edit my answer shortly ... – gunar Jun 08 '13 at 09:26
  • 1
    I did... my two last sentences explain that setTextSize is too imprecise for what I'm looking for. – francgo Jun 09 '13 at 18:49
  • @gunar no worries. People don't accept answers for various befuddling reasons. Your answer is good. I'm sure you'll get a good number of upvotes as time goes on. – Xavi Jun 10 '13 at 18:29
  • I'm not a hunter for accepted answers :) ... just that it makes me feel good when I know for sure that my answer really helped – gunar Jun 11 '13 at 05:59