-1

Currently learning on how to build an android app, my xml file should show the text Sup doge in the layout preview but its not showing at all.

Here's the pic: enter image description here

However, the text will show when I build the app & run it on an emulator: enter image description here

Now I have a problem where I need to constantly build the app just to see any small UI changes in the emulator when I'm supposed to view it in the layout instead.

UPDATE #1:

I tried Invalidate Cache & Restart which was suggested by @Khemraj & removed the constraint attributes. Also removed the tools:text="@string/app_name" part but its still showing blank in the layout preview. It still shows fine when building the app. enter image description here

Update #2:

Added background color to check. The preview has a problem. enter image description here

Update #3

Here are gradle folder files:

gradle-wrapper.properties file enter image description here

bulid.gradle file enter image description here

HeadFirstProject01 file enter image description here Anyone can help me fix this problem?

Solution:

Thanks to Khenraj's answer, I was using an unstable sdk ver so I had to update it to the previous stable ver & then build & sync gradle again:

    android {
        compileSdkVersion 27 //previously was 28
        defaultConfig {
            applicationId "com.example.headfirstproject_01.headfirstproject_01"
            minSdkVersion 14
            targetSdkVersion 27 //previously was 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1' //previously was 28.0.0-rc02
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Joshua Rajandiran
  • 2,788
  • 7
  • 26
  • 53
  • you need to change the `app_name` string in the strings folder (I think the issue is at `tools:text =@string/app_name"` –  Aug 31 '18 at 07:54
  • Try adding background on TextView, problem is preview is not working at all. – Khemraj Sharma Aug 31 '18 at 07:55
  • https://www.google.co.in/search?q=cant+see+layout+preview+androd&oq=cant+see+layout+preview+androd&aqs=chrome..69i57.7711j0j7&sourceid=chrome&ie=UTF-8 – Khemraj Sharma Aug 31 '18 at 07:56
  • use the attribute **android:layout_alignParentLeft="true"** also as the error is showing on your xml file – Deepak Kumar Aug 31 '18 at 07:56
  • See https://stackoverflow.com/questions/51591251/android-studio-textview-not-showing-in-design-view-layout/51591502#51591502 – Manohar Aug 31 '18 at 08:19

2 Answers2

1

The layout preview is not working. Use Invalidate Cache & Restart to see preview.

Suggestion:

RelativeLayout does not support constraint attributes. So remove those redundant constraint attributes from TextView.

Update

I seen many questions related this on SO. and answer is not one for all guys.

Here are few solutions:

  • Downgrade your sdk version. (compileSdkVersion, targetSdkVersion & support library versions)
  • Force refresh layout
  • Restart Android Studio
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
0

In you xml you are using

tools:text="@string/app_name"

tools:text is very useful when we design our layouts using the designer. What it does is very easy: act instead of android:text, but only in the designer's preview. This means that in your preview you'll see what you've specified in tools:text. This applies to everything starting with tools:. For example, you could also specify which layout the preview has to use to show a recyclerview's item. I guess that your app_name string is empty, and this is why you are not seeing anything in the preview.

Gregorio Palamà
  • 1,965
  • 2
  • 17
  • 22