【问题标题】:Why is `android:maxLines` ignored when I apply it indirectly via `TextAppearance`当我通过 `TextAppearance` 间接应用它时,为什么会忽略`android:maxLines`
【发布时间】:2019-12-10 11:14:54
【问题描述】:

当我通过TextAppearance 间接应用android:maxLines 时,为什么会忽略它

  <style name="TextAppearance.Footer">
    <item name="android:ellipsize">end</item>
    <item name="android:maxLines">1</item>
  </style>

  <style name="FooterButton">
    <item name="android:layout_gravity">center</item>
    <item name="android:textAppearance">@style/TextAppearance.Footer</item>
  </style>

我在documentation 中看不到 textAppearance 限制

直接设置属性就可以了:

  <style name="FooterButton">
    <item name="android:layout_gravity">center</item>
    <item name="android:ellipsize">end</item>
    <item name="android:maxLines">1</item>
  </style>

【问题讨论】:

  • android:maxLines 应用到视图为TextViewButton,而不是TextAppearance
  • @Gab 是的,但是为什么呢?
  • 检查@Froyo 的答案。 android:maxLines 属性不在 android:maxLines 中管理

标签: android textview styles


【解决方案1】:

你是对的。该文件没有指定任何限制。但鉴于它是 android 文档,它会缺少很多细节。从源代码中可以通过textAppearance设置以下属性。

    int mTextColorHighlight = 0;
    ColorStateList mTextColor = null;
    ColorStateList mTextColorHint = null;
    ColorStateList mTextColorLink = null;
    int mTextSize = 0;
    String mFontFamily = null;
    Typeface mFontTypeface = null;
    boolean mFontFamilyExplicit = false;
    int mTypefaceIndex = -1;
    int mStyleIndex = -1;
    int mFontWeight = -1;
    boolean mAllCaps = false;
    int mShadowColor = 0;
    float mShadowDx = 0, mShadowDy = 0, mShadowRadius = 0;
    boolean mHasElegant = false;
    boolean mElegant = false;
    boolean mHasFallbackLineSpacing = false;
    boolean mFallbackLineSpacing = false;
    boolean mHasLetterSpacing = false;
    float mLetterSpacing = 0;
    String mFontFeatureSettings = null;

mStyleIndex,不过是文字样式——bolditalic

您必须通过 xml 中的 styleandroid:maxLines 进行设置。

作为选择的理由,我可以说行数不属于文本外观的标准,而是属于视图的样式。

【讨论】:

    猜你喜欢
    • 2017-09-19
    • 2017-10-19
    • 2018-05-27
    • 1970-01-01
    • 2012-09-22
    • 2010-10-01
    • 2013-11-11
    • 2017-04-16
    • 1970-01-01
    相关资源
    最近更新 更多