You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android布局渲染错误:找不到@attr/textAppearanceButton求助

解决方案

错误1:Failed to find '@attr/textAppearanceButton' in current theme

原因

当前应用主题未继承包含textAppearanceButton属性的Material系列主题,或自定义主题未显式定义该属性。

解决步骤

  1. 打开res/values/styles.xml(或themes.xml),确保App主题继承Material组件主题,示例:
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- 其他主题配置 -->
    </style>
    
  2. 若使用自定义AppCompat主题,需在主题内显式指定textAppearanceButton对应的样式:
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="textAppearanceButton">@style/TextAppearance.MaterialComponents.Button</item>
        <!-- 其他主题配置 -->
    </style>
    

错误2:Style ResourceReference... is not of type STYLE (instead color)

原因

android:textAppearance属性要求传入样式资源(style),但你传入了颜色资源,类型不匹配。

解决步骤

  • 仅修改文字颜色:直接使用android:textColor替代android:textAppearance,示例:
    <Button
        android:id="@+id/register_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="注册"
        android:textColor="@color/teal_200" />
    
  • 自定义完整文字外观(含颜色、字号等):
    1. 在styles.xml中创建自定义样式:
      <style name="CustomButtonTextStyle" parent="TextAppearance.MaterialComponents.Button">
          <item name="android:textColor">@color/teal_200</item>
          <item name="android:textSize">16sp</item>
          <!-- 按需添加其他文字属性 -->
      </style>
      
    2. 布局中引用该样式:
      <Button
          android:id="@+id/register_btn"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="注册"
          android:textAppearance="@style/CustomButtonTextStyle" />
      

内容的提问来源于stack exchange,提问作者Bruh Brah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 21:50:24