Click here to Skip to main content
15,877,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello. i wanted to set my text size programmatically so in first step i added "dimen" tag in my dimen Xml file like this :

HTML
<dimen name="txtsize">20sp</dimen> 

after that i wrote 3 lines of code :
Java
tv=new TextView(this);
tv.setTextSize(R.dimen.txtsize);
tv.setText("hi guys !")

but unfortunately the text was disappeared ! please notice that if i change my code to this
Java
tv.setTextSize(20);

it works well ! but i dont want to set the text size directly .
please share your useful ideas with me . thanks ...
Posted

1 solution

try this:
tv.setTextSize(getResources().getDimension(R.dimen.txtsize));

Reference: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900