Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

android - 前景在实际设备中不可见,但在模拟器中可见(Foreground not visible in real device but visible in emulator)

When I'm setting a foreground for a button it show's fine on Android Studio but when I try it on my phone I cant see the picture selected.

(当我为按钮设置前景时,它在Android Studio上显示正常,但是当我在手机上尝试时,看不到所选图片。)

Here is a fresh project just to test this:

(这是一个新项目,仅用于测试:)

左边是手机屏幕截图,右边是Android Studio

Something wrong with Android Studio's preferences or its just my phone?

(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" />

And here is the Hello World's simple code.

(这是Hello World的简单代码。)

  ask by C.S. translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The android:foreground attribute is for a foreground selector (added to a FrameLayout).

(android:foreground属性用于前景选择器(添加到FrameLayout中)。)

It's not intended to simply draw an image.

(这并不是要简单地绘制图像。)

There is no attribute android:foreground for a textView .

(没有属性android:foregroundtextView 。)

and It also doesn't make sense to put a image in foreground on a textView .

(并且它也没有意义把一个图像中的前景上textView 。)

To learn more about the properties and methods for a textView follow Android developer page

(要了解有关textView的属性和方法的更多信息,请遵循Android开发者页面)

And if you like to add an image on your button then use imageButton.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...