自从谷歌推出com.android.support:appcompat-v7:28.0.0-alpha1
之后的新版本库以来,所有这些都无法在正确预览布局时起作用。我被迫使用com.android.support:appcompat-v7:28.0.0-alpha1
即alpha1
,尽管有新的存储库,如
28.0.0-rc02
28.0.0-rc01
28.0.0-beta01
28.0.0-alpha3
此外,我已经尝试改变布局,但似乎没有工作。这是我的gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.rish.myapplication"
minSdkVersion 19
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(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
}
并非Android Studio中的任何其他功能都受到影响(据我所知),因为已编译的应用程序仍能正常运行,但在没有预览的情况下工作很难。
我知道类似的问题已经存在,但除了更改存储库版本之外,这些问题都没有意义。我想知道这是我的电脑的问题还是与谷歌开发者有关。
我通过下载我的应用程序正在使用的所有SDK版本来修复此问题,结果证明版本28未完全安装!
它看起来在api 28中有一些bug尝试将它减少到api 27.使你的compileSdkVersion到27
compileSdkVersion 27
和你的targetSdkVersion到27
targetSdkVersion 27
并且
implementation 'com.android.support:appcompat-v7:27.1.1'
完整代码
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.rish.myapplication"
minSdkVersion 19
targetSdkVersion 27
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'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
}
这对我来说可以
否则改变你的主题,它也适用于我。
我将样式更改为Theme.AppCompat.Light.DarkActionBar
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
您可以尝试任何Theme.AppCompat.Light样式都可以正常工作不要忘记从xml布局文件和清单文件更改您的主题然后渲染问题将消失。
有同样的问题,并通过改变R.values.styles.xml中的值来解决它。
<style name="AppTheme"
parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!--customize your theme here-->
</style>
截至目前,问题已得到解决。使用com.android.support:appcompat-v7:28.0.0
(这是稳定的,现在被Android Studio使用)而不是com.android.support:appcompat-v7:28.0.0-XXXX
(XXXX
是rc
或beta
)将解决问题