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

查看:133
本文介绍了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:

<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 文件中.

They all need to inherit from AppCompat for your chosen layout. See the default working styles.xml file below. You can copy and paste it into your styles.xml file.

<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>

  1. 如果仍然有问题,请转到 app/manifests/AndroidManifest.xml 文件,并确保主题的值看起来像这样android:theme="@style/AppTheme.NoActionBar"android:theme="@style/AppTheme"它们是从上面列出的AppCompat主题继承的.
  1. If you are still having issues, go to the app/manifests/AndroidManifest.xml file and make sure that the value for the theme looks like this android:theme="@style/AppTheme.NoActionBar" or this android:theme="@style/AppTheme" this way they are inheriting from the AppCompat themes as listed above.

也请参见此处: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆