【问题标题】:android:background="@drawable/XXXX is ignored for a button in main.xmlandroid:background="@drawable/XXXX 对于 main.xml 中的按钮被忽略
【发布时间】:2011-07-14 15:07:54
【问题描述】:

我尝试复制几个不同的示例,使用形状布局,尝试图像等。无论我做什么,尽管背景可绘制对象被简单地忽略了。我故意将错误放入可绘制的 xml 以确保它被看到,这触发了错误。我在 res/drawable 中有我的可绘制内容。

有什么想法吗?

<Button android:id="@+id/buttonClose"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Test"`enter code here`
    android:padding="5dip"
    android:layout_gravity="center"
    android:layout_alignParentBottom="true"
    android:onClick="closeScoreBoard"
    android:background="@drawable/button_close"
    />


<?xml version="1.0" encoding="UTF-8"?>
<shape      xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid   android:color="#FF0000"/>

    <corners
        android:bottomRightRadius="8dip"
        android:bottomLeftRadius="8dip"
        android:topLeftRadius="8dip"
        android:topRightRadius="8dip"
/>
</shape>

【问题讨论】:

  • 你可以为按钮发布你的 XML 吗?
  • 请将它们添加到您的问题中并格式化它们以便于阅读。
  • 完成,稍早于您的要求...
  • 你的背景是什么?是图像吗?如果有,是什么类型的?您在 LogCat 中看到任何错误吗?

标签: android xml layout drawable


【解决方案1】:

随便用

<androidx.appcompat.widget.AppCompatButton 

它帮助了我。

【讨论】:

    【解决方案2】:

    改变背景不会被忽略。由于前景可绘制,简单的背景不可见。您可以在这里找到更多信息:Standard Android Button with a different color

    或准备在此处使用示例:http://ogrelab.ikratko.com/custom-color-buttons-for-android/

    【讨论】:

    • 那么我可以改变什么让它可见?
    【解决方案3】:

    到处搜索后,我得到了这个解决方案,它工作正常。 转到价值观 > 主题

    1. 将父主题从 Theme.MaterialComponents.DayNight.DarkActionBar 更改为“Theme.AppCompat.DayNight.DarkActionBar”

    2. 粘贴在“”之前

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-14
      • 2021-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-31
      相关资源
      最近更新 更多