Georgi Stephanov
Georgi Stephanov

Reputation: 45

Android studio - TextView showing on preview but not emulator/device

I started the "Android 6 for Programmers: An App-Driven Approach" book and ran into a problem. I was following the step-by-step approach for one of the apps and got a pretty frustrating error that I cannot fix.

I've added a text and image views and on the Preview section they are shown as they should be but when I run the app on the emulator or on an actual device the text seem to be missing. I am going to attach photos below for more clarity.

The custom colour is Material Blue 500 (#2196F3). Tried changing it to another but the problem doesn't seem to be affected by it. The text size is 40sp (80sp on a > 600x600 device).

enter image description here

enter image description here

Upvotes: 1

Views: 4188

Answers (3)

OneCricketeer
OneCricketeer

Reputation: 191758

When using a LinearLayout and layout weights, set height in your case to 0dp for both the text and image

If you're wanting to center things and align to each other, RelativeLayout or ConstraintLayout would be preferred.

Upvotes: 0

pRaNaY
pRaNaY

Reputation: 25312

You need to change tools:text to android:text. Using tools attribute you can only see preview in design time.

Upvotes: 10

Lutaaya Huzaifah Idris
Lutaaya Huzaifah Idris

Reputation: 3990

Try to remove Layout weight, it might be the problem .

Upvotes: 0

Related Questions