2015-11-27 79 views
3

我是Android Studio的新手。我在activity_main.xml標籤下找到了這個問題。所以,如何解決這個問題。我已經安裝了android studio 1.4.1 bundle離線。此外,我不能拖放小工具,電話activity_main.xml.But我可以拖動和content_main.xml下降Android Studio中的渲染問題

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 

這是我在文字

<?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> 
+0

裏面你可以發佈你的activity_main.xml中? – Gi0rgi0s

+0

@ Gi0rgi0s嘿,我已經發布了。看一看 –

回答

1

由於您的MainActivity擴展了AppCompatActivity,因此它的主題大部分來自AppCompat。要解決此問題,更正如下:

  1. 打開文件應用程序/ RES /價值/ styles.xml
  2. 變化在styles.xml文件中以下行看起來像這樣:

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

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

他們都需要從繼承AppCompat爲您選擇的佈局。請參閱下面的默認工作styles.xml文件。您可以將其複製並粘貼到您的styles.xml文件中。

<resources> 
    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 
    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 
</resources> 
  • 如果您仍然有問題,轉到應用程序/艙單/ AndroidManifest.xml中文件,並確保爲主題的價值看起來像這樣android:theme="@style/AppTheme.NoActionBar"或這android:theme="@style/AppTheme"這種方式,他們從上面列出的AppCompat主題繼承。
  • 看這裏還有:You need to use a Theme.AppCompat theme (or descendant) with this activity

    +0

    styles.xml和你說的一樣。我的意思是它正是你所說的。而且我仍然在activity_main.xml下找到了錯誤 –

    +0

    您是否檢查過清單? – Gi0rgi0s

    +0

    是的,它也相同.. –

    1

    父activity_main.xml中AppTheme需要是小孩或者Theme.AppCompat。請在您的代碼中檢查樣式:@style/AppTheme

    0

    添加android:theme="@style/Theme.AppCompat.Light"CoordinatorLayout