【问题标题】:Android icon mipmap value not working on buttonAndroid图标mipmap值在按钮上不起作用
【发布时间】:2017-05-05 10:15:14
【问题描述】:

我正在尝试获取一个带有可在 Android 上运行的图像的按钮。我尝试了以下方法:

<Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:icon="@mipmap/ic_launcher" />

按钮显示时没有图像。

【问题讨论】:

  • 你想把图片放在哪里?
  • 我只想要一个带有图像而不是文本的按钮。图片在 res/mipmap 文件夹中,android studio 在你导入图片资源后把它放在这里。
  • 您不应将mipmap 文件夹用于应用程序图标之外。对于图形资源,请使用drawable

标签: android android-mipmap


【解决方案1】:

#。如果你想要一个只有背景的Button Image,试试这个:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/ic_launcher"/>

或者,您可以使用ImageButton,如下所示:

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/ic_launcher" />

#。如果你想要 ButtonText 和背景 Image,试试这个:

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BUTTON"
    android:background="@mipmap/ic_launcher"/>

#。如果你想要一个ButtonText 并留下可绘制的Icon,试试这个:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BUTTON"
    android:drawableLeft="@mipmap/ic_launcher"/>

【讨论】:

    【解决方案2】:

    试试

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@mipmap/ic_launcher" />`
    

    【讨论】:

    • 这似乎可以解决问题。找到解决方案有点hacky,但就足够了。谢谢!
    • 如果有用,请接受答案。干杯
    猜你喜欢
    • 2015-03-01
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多