Failed to load AppCompat ActionBar with unknown error. as不显示布局

版权声明:独学而无友,则孤陋寡闻。q群582951247 https://blog.csdn.net/mp624183768/article/details/82768982

我原来用的是2.3版本 ,在升级最新的android studio3.1后,发生了一些变化,新建项目从以前的LinearLayout变成了ConstraintLayout,好像是谷歌16年底推出的一个新布局。

我按照原来的方法添加控件,发现preview不能正常显示,提示如下

The following classes could not be instantiated:
- android.support.v7.widget.ActionBarContainer (Open Class, Show Exception, Clear Cache)
- android.support.v7.widget.ActionBarContextView (Open Class, Show Exception, Clear Cache)
- android.support.v7.app.WindowDecorActionBar (Open Class, Show Exception, Clear Cache)

 Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.

If this is an unexpected error you can also try to build the project, then manually refresh the layout.

我以为的导入的包问题,后来捣鼓半天无果,在Stack Overflow上发现了类似的问题

链接https://stackoverflow.com/questions/44223687/render-error-in-android-studio-3-0-layout-editor

一个回复提到修改styles.xml

 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

</style>

to:

 
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

</style>

试了一下果然可以正常显示了

猜你喜欢

转载自blog.csdn.net/mp624183768/article/details/82768982