csima
csima

Reputation: 325

TextView shows in AndroidStudio but not on device nor DebugMonitor

I have a popup which is shown when I receive a GCM notification. The popup is implemented as a LinearLayout which is setContentView'd in the popup activity. The layout render in Android Studio looks like this:

screenshot of Android Studio

However, on the device and on the DebugMonitor View Hierarchy dump it does not show, although it is there:

screenshot of DebugMonitor's View Hierarchy dump

The TextView has the default text "Where?" replaced in the extended Activity class:

    String lightName = getIntent().getStringExtra(LIGHT_NAME_KEY);
    final TextView lightNameLabel = (TextView) findViewById(R.id.lightNameLabel);
    lightNameLabel.setText(lightName);

I am at a loss here. I grep'ed through the project files and there are no other uses of the TextView's id other than in the snippet above. Could you please give me some pointers where to investigate why the TextView doesn't show?

[edit] I am including the .xml snippet for the respective TextView:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/lightNameLabel"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="1dp"
    android:text="Where?"
    android:visibility="visible" />

[edit 2] A link to the whole layout .xml file: http://pastebin.com/2uqkzBSa

Upvotes: 1

Views: 2999

Answers (1)

Paul Lammertsma
Paul Lammertsma

Reputation: 38252

It was helpful that you showed a screenshot, as the problem is likely that you're displaying the layout in a dialog. If you select the Holo dialog theme in Android Studio's graphical editor pane, you'll observe that the default text color is white. Since you've provided a light background, the light text is simply illegible against it.

There are different solutions:

  • Provide a different theme when displaying the dialog as to ensure that the primary colors are dark; or
  • Define your own theme and provide it when displaying the dialog; or
  • Modify the layout to specify a text color.

Upvotes: 4

Related Questions