问题
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
- changing app theme to holo.light
- adding
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">tores>styles.xml - 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.
回答1:
Try this:
compileSdkVersion 27
buildToolsVersion '27.0.1'
targetSdkVersion 27
Hope this will help.
回答2:
Try with this
com.android.support:recyclerview-v7:20.0.+
or remove alpha and try it
回答3:
I think you should try changing your sdk version and using an older version of recyclerview (probably version 27) and other libraries you used to see if it works.
回答4:
Try doing 'Invalidate Cache / Restart' in 'File' in Android Studio.
If this doesn't work then try the following:
Add this to your build.gradle (project) file :
configurations.all {
resolutionStrategy {
force 'com.android.support:recyclerview-v7:28.0.0-alpha3'
}
}
来源:https://stackoverflow.com/questions/51723986/recyclerview-preview-showing-grey-screen-with-android-support-v7-widget-recycler