2014-10-30 41 views
1

我剛開始一個新項目,並且我一直在嘗試使用新的Material Design AppCompat(v21)幾天,但每次我試着把一個像CardView那樣的小工具或者新的工具欄放到一個不讓屏幕繪製它們的錯誤中。我嘗試使用幾乎所有AppCompat v21小部件時出現錯誤

例如,這樣的代碼:

<?xml version="1.0" encoding="utf-8"?> 

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" android:layout_width="match_parent" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_margin="5dp" 
    card_view:cardCornerRadius="5dp" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="100dp"> 


    </RelativeLayout> 

</android.support.v7.widget.CardView> 

返回此錯誤:

The following classes could not be instantiated: 
- android.support.v7.widget.CardView (Open Class, Show Exception) 

此外,使用此代碼:

<android.support.v7.widget.Toolbar 
     android:id="@+id/my_awesome_toolbar" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:minHeight="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" /> 

返回此錯誤:

Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the  layout to choose a different layout, or fix the theme style references. Failed to find style  'toolbarStyle' in current theme (6 similar errors not shown) 

我已經將AppCompat添加到Gradle構建中,並使用Theme.AppCompat.Light以及從ActionBarActivity進行擴展。

我做錯了什麼?先進的謝謝你。

回答

1

我認爲這只是佈局編輯器的錯誤。

嘗試運行該應用程序以查看是否存在實際錯誤。

+0

是的,它的工作原理!我不知道它只是一個佈局編輯器的bug,但它的作用就像魅力。希望Google儘快修復它,但是,爲了看到我正在開發的設計,必須執行該應用程序有點煩人。 – spaceisstrange 2014-10-31 16:47:18

+0

謝謝Fauzie。它仍然沒有在Android Studio v1.5中修復! – 2016-01-30 06:35:47

+0

不是bug,正確的sintax是: ?android:attr/actionBarSize – aorlando 2016-11-04 16:48:52

相關問題