使用android.support.design.widget.CoordinatorLayout时删除标题栏而不影响样本布局的呈现

时间:2016-08-31 23:11:16

标签: android android-layout

我想删除我正在处理的应用程序中的标题栏,我将其写为空活动,但我怎么会遇到这些错误

   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.NoClassDefFoundError: android/support/design/R$styleable   at
   android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:187)
   at android.support.design.widget.CoordinatorLayout.<init>CoordinatorLayout.java:179)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

这是我的activity_main.xml文件

    <?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_width="match_parent"
         android:layout_height="wrap_content"
         android:theme="@style/AppTheme.AppBarOverlay"
         app:elevation="0dp">

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


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

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:paddingBottom="@dimen/activity_vertical_margin"
         android:paddingLeft="@dimen/activity_horizontal_margin"
         android:paddingRight="@dimen/activity_horizontal_margin"
         android:paddingTop="@dimen/activity_vertical_margin"
         app:layout_behavior="@string/appbar_scrolling_view_behavior">

     </LinearLayout>

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

我的styles.xml文件是          

<!-- 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>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

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

最后我的module.gradle for module.app是         apply plugin:'com.android.application'

android {     compileSdkVersion 24     buildToolsVersion“24.0.1”

defaultConfig {
    applicationId "com.captureinc.capture"
    minSdkVersion 21
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
    }
    dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.1.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
     }
     apply plugin: 'com.google.gms.google-services'

1 个答案:

答案 0 :(得分:0)

第一百万次,你不能混合支持库的版本:

compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.1.0'

此外design取决于appcompat-v7,并会自动将其拉出来,这样就可以了:

compile 'com.android.support:design:24.2.0'