Search code examples
androidtextformattingsizedensity-independent-pixel

Should I use dip, dp, sip or sp for text formatting?


I wouldn't say my app is text heavy...but it displays random strings sometimes that are longer than others. They fit fine on my droid 2, but I know they won't display the same on smaller droids. Does anyone know the proper way of formatting different sized text to ensure it will work on all androids?


Solution

  • If you just want to make some text bigger or smaller you should prefer using default styles provided by Android:

    <TextView ... android:textAppearance="?android:attr/textAppearanceMedium" />
    <TextView ... android:textAppearance="?android:attr/textAppearanceLarge" />
    <TextView ... android:textAppearance="?android:attr/textAppearanceSmall" />
    

    Neither of them is default, default is:

    <TextView ... android:textAppearance="?android:attr/textAppearance" />
    

    It can be surely applied not only to TextView, but to other views as well.