2012-07-21 39 views
153

是否有關默認的DPI值的文檔(或任何人)會談dpi值看待安卓

  • 大的TextView {android:textAppearance="?android:attr/textAppearanceLarge"}
  • 中等的TextView {} android:textAppearance="?android:attr/textAppearanceMedium"
  • 小的TextView {} android:textAppearance="?android:attr/textAppearanceSmall"

部件的SDK?

The Large, medium, small and regular text views

爲了把它以另一種方式,我們可以複製這些文本視圖的外觀,而不使用android:textAppearance屬性?

+1

如果您使用的是產品的IntelliJ如Android Studio中,您將能夠每當你按'機器人F1查看文檔:textAppearanceValue'這會給你的尺寸sp/dp的值。 – androidtitan 2017-09-27 18:20:57

回答

262

請參閱android sdk目錄。

\platforms\android-X\data\res\values\themes.xml

<item name="textAppearanceLarge">@android:style/TextAppearance.Large</item> 
    <item name="textAppearanceMedium">@android:style/TextAppearance.Medium</item> 
    <item name="textAppearanceSmall">@android:style/TextAppearance.Small</item> 

\platforms\android-X\data\res\values\styles.xml

<style name="TextAppearance.Large"> 
    <item name="android:textSize">22sp</item> 
</style> 

<style name="TextAppearance.Medium"> 
    <item name="android:textSize">18sp</item> 
</style> 

<style name="TextAppearance.Small"> 
    <item name="android:textSize">14sp</item> 
    <item name="android:textColor">?textColorSecondary</item> 
</style> 

TextAppearance.Large意味着風格是從TextAppearance風格繼承,你必須追蹤它,如果你還希望看到一個風格的完整定義。

鏈接:http://developer.android.com/design/style/typography.html

12

爲了把它以另一種方式,我們可以複製這些文本視圖的外觀,而不使用了android:textAppearance屬性?

biegleux已經說過:

  • 表示器14sp
  • 媒體代表18SP
  • 代表22sp

如果您想使用在Android應用的任何文字值,你可以在你的values文件夾中創建一個dimens.xml文件,並用以下3條線路有定義文字大小:

<dimen name="text_size_small">14sp</dimen> 
<dimen name="text_size_medium">18sp</dimen> 
<dimen name="text_size_large">22sp</dimen> 

這裏是從dimens.xml文件文本一個TextView的例子:

<TextView 
    android:id="@+id/hello_world" 
    android:text="hello world" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="@dimen/text_size_large"/> 
3

編程,你可以使用:

textView.setTextAppearance(android.R.style.TextAppearance_Large);