2012-07-21 22 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);