Android, trying to enlarge text if it's on a bigger screen -


i trying enlarge size of text in button screen gets wider. @ first seemed code worked, on different android devices not work. change font big size on small screen.

this i'm doing:

 int w=getwindowmanager().getdefaultdisplay().getwidth();          button but1=new button(this); //        but1.settextcolor( color.parsecolor("#ffd79825"));          if (w<400)             but1.settextsize(10.0f);         else         if (w<650)             but1.settextsize(14.0f);         else              if (w>470)                 but1.settextsize(18.0f); 

why making more complicated, is?

just use dimensions in values folder:

values:

<dimen name="txtsize">10dp</dimen> 

values-sw400:

<dimen name="txtsize">14dp</dimen> 

and on.

you can obtain value this:

resources res = getresources(); float fontsize = res.getdimension(r.dimen.txtsize); 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -