安卓系统默认的“大号”、“中号”和“小号”文本视图的dpi值是多少?

175

文档(或其他人)是否提及默认小部件的dpi值?

  • Large TextView {android:textAppearance="?android:attr/textAppearanceLarge"} 大型文本视图
  • Medium TextView {android:textAppearance="?android:attr/textAppearanceMedium"} 中等文本视图
  • Small TextView { android:textAppearance="?android:attr/textAppearanceSmall"} 小型文本视图

大型,中型,小型和常规文本视图

换句话说,我们可以不使用android:textAppearance属性来复制这些文本视图的外观吗?


1
如果您正在使用IntelliJ产品,例如Android Studio,每当您按F1键时,您将能够查看文档,其中包括android:textAppearanceValue的sp/dp大小值。 - androidtitan
3个回答

286

请查看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


19
换句话说,我们是否可以在不使用android:textAppearance属性的情况下复制这些文本视图的外观?就像 biegleux已经说过的那样:
- small 表示 14sp - medium 表示 18sp - large 表示 22sp 如果您想在Android应用程序中的任何文本上使用smallmediumlarge值,您只需在values文件夹中创建一个dimens.xml文件,并在其中定义文本大小,如下所示:
<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"/>

9

从编程角度来说,您可以使用以下方法:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接