I'm using webView to display HTML content.
The text size is readable for tablets. However on small smartphones, the text appears as dots. The user has to pinch-zoom to read it.
Is there any way to set a fixed size which will be readable on both tablets and smartphones?
WebSettings ws= webView.getSettings();
setTextSize:
ws.setTextSize(ws.TextSize.NORMAL);
Enum for specifying the text size.
SMALLEST is 50%,
SMALLER is 75%,
NORMAL is 100%,
LARGER is 150%,
LARGEST is 200%,
Or use this one
ws.setDefaultFontSize(12);
Related
I have a webpage where the font-size of body 16px.
On Google Chrome for Android, I have the following problem: When the page initially loads, the font size in elements which don't have a font-size defined (and therefore inherit the font-size from the body) is bigger than 16px (as you will see if you read on, there is no obvious way to calculate the multiple to which the size of the rendered text is bigger). When the user scrolls down the rendered text size changes to 16px.
See the two images below for a visualisation
In the above screenshot the page has loaded and the user has not interacted with the page.
In the above screenshot the page has loaded and the user has interacted with the page. Notice how the font size on the element showing "0% interest" is now smaller
When the text is larger and smaller - both sizes compute as 16px
Despite the fact that there is a visual difference between the two font-sizes. Before the user scrolls and the text is larger and after the user scrolls and the text size is smaller — the font-size in all cases computes as 16px.
In the above image we can see that the font-size is in both cases 16px but that the two rendered texts are clearly different in size
What happens if the size is changed?
If I change the of the text, the rendered text size increases or decreases (depending on whether or not the number is greater or less than 16). In both cases though the text size increases in proportion to the original text size.
It seems like the browser is showing 16px as a certain size and that it then changes this size when the user scrolls.
Here I've increased the font-size to 20px. Whilst the font size does increase, it increases in proportion to the original rendered text size
Could Javascript be responsible this?
I don't think so. I have disabled javascript in the browser and reloaded the page and the problem still persists.
Does anyone have an idea about what might be causing this?
There are two solutions around:
As described here Chrome on android resizes font the issue occurs if any text reach a certain length.
Add "max-height: 999999px;" to the element which is surrounding the text.
<meta name="viewport" content="width=device-width, initial-scale=1">
For me solution no 1 worked.
There is so-called font size "adjusting". Try to disable it:
text-size-adjust: none;
-webkit-text-size-adjust: none;
-moz-text-size-adjust: none;
-ms-text-size-adjust: none;
See details: https://developer.mozilla.org/en-US/docs/Web/CSS/text-size-adjust
When i present my textview, i setup a font size of say 18. But if the user set in his phone setting to use a large font size, then my textview will be show with font much bigger than 18. How to force My text view to show with a font size exactly of 18 ?
It is because you are using 18sp. If you will use 18dp then it will not change the font size. But for font sizes "sp" is preferable so that user can increase or decrease the font size.
For more details check this link,
Difference between dp and sp
For your case, You can use this,
You can use:
float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 18, getResources().getDisplayMetrics());
editText.setTextSize(pixels);
Now the value of pixels is equivalent to 18dp at the device's current screen density.
The TypedValue contains other similar methods that help in conversion.
I am creating an extremely simple web page: it simply shows images one after the other until the bottom of the page.
Problem is... I am not sure what size images we should be using.
What is the ideal width of the images in a vertical browser?
Does this differ between android and iphone?
Just use the viewport size tag so the mobile devices will automatically resize the page to the correct dimensions.
You can for example just make a page which is 1024 pixels wide and define the viewport meta tag to be 1024px so all screens know it is supposed to be rendered as if the total screen width is 1024 px.
<meta name="viewport" content="width=1024">
This way you don't have to change the width of your design for each device. The device will scale the page for you to fit the screen.
Most mobile sites use a 480px width. Perhaps to improve loading time you better also use a smaller one since smaller images load faster and the phone will resize them anyway.
PS: Works on all modern devices across all platforms.
I am making a mobile site, and trying to do it so the title h1 tag will adjust to 80% of the screen size.
According to CSS Values and Units Module Level 3 (Candidate Recommendation), you can use the vh unit, which is equal to 1% of the width of the initial containing block. So for example, font-size: 5vh would set font size to 5% of the body width. Browser support is fairly good in newest versions, but this excludes e.g. IE 8. This more or less answers the question in the title.
The description in the body of the question is something rather different. The font size is the height of the font and does not have any defined relationship with the widths of letters (which vary), so there is really no way in CSS to make some text occupy 80% of some width. You can set the width of an h1 element of course, but this is very different from setting the width of its text content. You would need JavaScript to set the text width.
Font size can't be use as percentage (%)
you can use em and px extensions for font size
for example
font-size:2 em;
or
font-size:10px;
I have an Android app that looks absolutely horrible if the user sets their font size to large or extra large (via Settings -> Display -> Font size in Ice Cream Sandwich). It just plain wasn't designed for variable font sizes, and it makes a lot of the text unreadable.
I've seen applications that preserve the font size for most views, so I know that there has to be a way to do this. Is there a simple way for me to tell the application to ignore the user's font size preference? And if there isn't, how would you suggest that I go about calculating the font sizes? If nothing else, is there a way for me to retrieve the user's font size preference?
I think what you want to do is specify your font sizes in "dp" instead of "sp". All sp units take user font size preferences into account when adjusting their size, while dp units only calculate size based on the device's pixel density.