Android Studio 中的渲染问题 [英] Rendering Issue in Android Studio

查看:29
本文介绍了Android Studio 中的渲染问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android Studio 的新手.我在 activity_main.xml 选项卡下遇到了这个问题.那么,如何解决这个问题.我已经离线安装了 android studio 1.4.1 包.此外,我无法在activity_main.xml 中将小部件拖放到电话中.但我可以在content_main.xml 中拖放

I am new to Android Studio.And I came accross this problem under activity_main.xml tab . So, How to fix this.I have installed the android studio 1.4.1 bundle offline. Also I can't drag and drop widgets to phone in activity_main.xml.But I can drag and drop in content_main.xml

 Rendering Problems
 The following classes could not be instantiated:
- android.support.design.widget.CoordinatorLayout (Open Class, Show Exception, Clear Cache)
- android.support.design.widget.AppBarLayout (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 

Exception Details  

 java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.  
 at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:34)  
 at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:178)   
 at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:172)  
 at java.lang.reflect.Constructor.newInstance(Constructor.java:422)   
 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)   
 at android.view.LayoutInflater.inflate(LayoutInflater.java:492)   
 at android.view.LayoutInflater.inflate(LayoutInflater.java:394) 
  Copy stack to clipboard

这是我的activity_main.xml 文本

Here is my activity_main.xml in text

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
    android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
        android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<android.support.design.widget.FloatingActionButton android:id="@+id/fab"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />
   </android.support.design.widget.CoordinatorLayout>

推荐答案

由于你的 MainActivity 扩展了 AppCompatActivity,它的主题大部分来自 AppCompat.要解决此问题,请更正以下内容:

Since your MainActivity extends AppCompatActivity, its theme most be from AppCompat. To fix this issue, correct the following:

  1. 打开文件app/res/values/styles.xml
  2. styles.xml 文件中的以下几行更改为如下所示:
  1. Open the file app/res/values/styles.xml
  2. Change the following lines in the styles.xml file to look like this: