【问题标题】:How to get CheckBox or RadioButton textAppearance?如何获取 CheckBox 或 RadioButton textAppearance?
【发布时间】:2013-09-17 20:11:51
【问题描述】:

我的布局中有一些单选按钮和/或复选框,我希望我周围的 TextViews 具有相同的文本外观(大小、颜色等)。

基本上,我正在寻找类似以下的内容:

<TextView
    android:textAppearance="?android:attr/textAppearanceRadioButton"
    ...
/>

是否有可能以其他方式实现这一目标?

P.S:我不想更改单选按钮和复选框已有的“默认”文本外观。另外,我不是在寻找运行时解决方案,而是使用 xml 布局文件的解决方案。

【问题讨论】:

    标签: android radio-button android-checkbox


    【解决方案1】:

    我现在找到了,这似乎至少适用于Theme.HoloTheme.Holo.Light

    android:textAppearance="?android:attr/textAppearance"
    android:textColor="?android:attr/textColorPrimaryDisableOnly"
    

    这些是在CheckBox 上设置的两个没有在TextView 上设置的东西。

    【讨论】:

      【解决方案2】:

      根据 Android API 文档(强调我的):

      android:textAppearance

      基本文本颜色、字体、大小和样式。

      必须是对另一个资源的引用,格式为“@[+][package:]type:name”或主题属性格式为“?[package:][type :]名字”。

      这对应于全局属性资源符号textAppearance。

      这表明您只需要在TextViews 的android:textAppearance 属性中引用您在RadioButtons 中使用的相同资源。

      【讨论】:

      • 我在单选按钮中使用默认文本外观。我怎样才能引用那个?
      • 您的其他TextViews 上的默认外观不一样吗?
      • 不,(例如)单选按钮的默认文本外观,在大小和颜色上都与文本视图的默认外观不同。
      猜你喜欢
      • 1970-01-01
      • 2010-11-25
      • 1970-01-01
      • 2012-04-12
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 2014-03-21
      • 2011-03-27
      相关资源
      最近更新 更多