【问题标题】:dpi value of default "large", "medium" and "small" text views android默认“大”、“中”和“小”文本视图的 dpi 值 android
【发布时间】:2012-07-21 08:07:09
【问题描述】:

文档(或任何人)是否讨论了默认的 dpi 值

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

SDK 中的小部件?

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

【问题讨论】:

  • 如果您使用的是 IntelliJ 产品,例如 Android Studio,您将能够在android:textAppearanceValue 上按 F1 时查看文档,这将为您提供值的 sp/dp 大小。

标签: android textview android-xml


【解决方案1】:

在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

【讨论】:

    【解决方案2】:

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

    就像biegleux 已经说过的:

    • 代表14sp
    • 代表18sp
    • 代表22sp

    如果您想在 Android 应用中的任何文本上使用 smallmediumlarge 值,您只需创建一个 @ 987654322@ 文件在您的values 文件夹中,并在其中使用以下 3 行定义文本大小:

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

    这是一个 TextView 的示例,其中包含来自 dimens.xml 文件的 文本:

    <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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-02
        • 2021-09-20
        • 2013-01-12
        • 2018-10-11
        • 1970-01-01
        • 2016-05-02
        • 1970-01-01
        相关资源
        最近更新 更多