How do I set the same text size in an Android app?

I am wondering how to make the MainScreen text the same for all devices (I am using android studio) I have 65dp text, but as soon as I run it on an emulator that has more screen, my text is much smaller.

+3


source to share


3 answers


Never use "dp" to specify texts. Always use "sp" for text and "dp" for everything else.



android:textSize="25sp"

android:layout_width="50dp"

      

+1


source


You can use the current screen resolution and the text size will be proportional for each individual device. Thus, you can use something like this:

//get your textView
TextView text = (TextView) findViewById(R.id.titleField);
text.setText("Your title here");
text.setTextSize(65 * getResources().getDisplayMetrics().density);

      



you can do this for every TextView on your MainScreen. Hope this helps you :)

PS You can find more suggestions for your case here: Text size with different resolutions

0


source


please check fooobar.com/questions/74399 / ...

Blockquote

WarrenFaith The compiler accepts both "dip" and "dp", although "dp" is more appropriate for "sp".

0


source







All Articles