0

In my application I am using a style for textViews with distinct textSize. However based on different device's screen size, I have to change the textSize of all the textView. I can't call all the textViews one by one and change the textSize based on the screen size. So is there any way I can change the style attribute programatically based on the required conditions so that I don't have to set the text size individually?I think people have already asked this questions many times. Still I was unable to find an exact answer for my query.

Animesh Jena
  • 1,458
  • 1
  • 15
  • 40
  • Out of interest, what is your purpose for changing the textSize independent from the native Android scaling? – zgc7009 Jun 08 '16 at 13:38
  • @zgc7009- Actually the scaling is not helping much in case of huge difference in screen sizes and then the screen is also devided in to small parts through different layouts where each layouts carry a lot of informations. I am not allowed to use a scroller in case of very small devices too and it has to fit the whole screen. – Animesh Jena Jun 08 '16 at 13:43
  • 1
    You may want to rework your layouts to fall more into the guideline patterns of Android. If you insist on managing scaling on your own you can use resolution dependent values... http://stackoverflow.com/questions/9877946/text-size-and-different-android-screen-sizes – zgc7009 Jun 08 '16 at 14:04
  • 1
    The best practice to solve this problem would be to create a different layout for different ranges of screen sizes. That way you don't have to try to design one layout that will look good on a 4 inch screen and a 10 inch screen. https://developer.android.com/guide/practices/screens_support.html – Kevin Klute Jun 08 '16 at 14:22
  • Thank you @zgc7009....your suggestions really helped – Animesh Jena Jun 10 '16 at 04:46
  • @Kevin Klute..thank you..it was very helpful – Animesh Jena Jun 10 '16 at 04:46

1 Answers1

0

You could use HTML in your TextViews.

textview.setText(Html.fromHtml("<h2>Title</h2><br><p>This is <b>bold</b> <font size="6">this is smaller</font>,<font size="20">this is bigger</font></p>"));

Output:

Title


This is bold this is smaller,this is bigger

rib
  • 170
  • 9