Search code examples
androidandroid-studioandroid-recyclerviewandroid-coordinatorlayout

Recyclerview preview showing grey screen with android.support.v7.widget.RecyclerView in center


I am trying to add Recyclerview to my activity layout but the layout preview shows me this. I went through all possible answers which i could find out and tried doing things like

  1. changing app theme to holo.light
  2. adding <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> to res>styles.xml
  3. went through all possible relating questions like this and this as well and made changes accordingly in my code.

My build.gradle file is as follows:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.1'
    defaultConfig {
        applicationId "com.myapp.test"
        minSdkVersion 21
        targetSdkVersion 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(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-v4:28.0.0-alpha3'
    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'
    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
    implementation 'com.android.volley:volley:1.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'

}

The same problem occurs when i am trying to use coordinate layout as well in my activity. I am using android studio 3.1.3 and my device that m targeting is of oreo version.

I am not able to figure out whats the problem. Kindly help me out.


Solution

  • Try this:

    compileSdkVersion 27
    buildToolsVersion '27.0.1'
    targetSdkVersion 27
    

    Hope this will help.