前景在实际设备中不可见,但在模拟器中可见

问题描述 投票:2回答:2

[当我为按钮设置前景时,它在Android Studio上显示正常,但是当我在手机上尝试时,看不到所选图片。这是一个用于测试此项目的新项目:

Left is from phone screenshot, right is from Android Studio

Android Studio的偏好设置或我的手机有问题吗?

<TextView
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:text="Hello World!"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:foreground="@mipmap/ic_launcher"
    android:foregroundGravity="center" />

这是Hello World的简单代码。

android android-layout android-studio android-image
2个回答
3
投票

android:foreground属性用于前景选择器(添加到FrameLayout中)。它并非旨在简单地绘制图像。

android:foreground没有属性textView。并且将图像放在textView上的前景中也没有意义。要了解有关textView的属性和方法的更多信息,请遵循Android developer page

如果您想在按钮上添加图像,请使用imageButton。


1
投票

或者,我添加了带有android:drawableLeft的图像(在我的情况下,左侧是可以的),并且显示的还好。因此,如果有人遇到类似的问题,android:drawableLeft也会起作用。

© www.soinside.com 2019 - 2024. All rights reserved.