2016-07-22 54 views
2

我正在使用Custom Action BarAndroid Holo Colors Generator向我的android應用程序實現主題設計。操作欄樣式工作正常。但是,使用Android Holo Colors Generator實現自定義主題時會出現問題。這些錯誤是android中的自定義主題設計問題

com.myapp.testing.theme E/AndroidRuntime: FATAL EXCEPTION: main 
    Process: com.myapp.testing.theme, PID: 25491 
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.testing.theme/assetviewer.findergpstracking.com.finder.activity.HomeActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3124) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3233) 
    at android.app.ActivityThread.access$1000(ActivityThread.java:197) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:145) 
    at android.app.ActivityThread.main(ActivityThread.java:6856) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 
    Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout 
    at android.view.LayoutInflater.createView(LayoutInflater.java:640) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750) 
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:904) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:511) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:366) 
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
    at assetviewer.findergpstracking.com.finder.activity.HomeActivity.onCreate(HomeActivity.java:152) 
    at android.app.Activity.performCreate(Activity.java:6550) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3077) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3233)  
    at android.app.ActivityThread.access$1000(ActivityThread.java:197)  
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)  
    at android.os.Handler.dispatchMessage(Handler.java:102)  
    at android.os.Looper.loop(Looper.java:145)  
    at android.app.ActivityThread.main(ActivityThread.java:6856)  
    at java.lang.reflect.Method.invoke(Native Method)  
    at java.lang.reflect.Method.invoke(Method.java:372)  
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)  
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)  
    Caused by: java.lang.reflect.InvocationTargetException 
    at java.lang.reflect.Constructor.newInstance(Native Method) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:614) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)  
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:904)  
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)  
    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)  
    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)  
    at android.view.LayoutInflater.inflate(LayoutInflater.java:366)  
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)  
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)  
    at assetviewer.findergpstracking.com.finder.activity.HomeActivity.onCreate(HomeActivity.java:152)  
    at android.app.Activity.performCreate(Activity.java:6550)  
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)  
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3077)  
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3233)  
    at android.app.ActivityThread.access$1000(ActivityThread.java:197)  
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)  
    at android.os.Handler.dispatchMessage(Handler.java:102)  
    at android.os.Looper.loop(Looper.java:145)  
    at android.app.ActivityThread.main(ActivityThread.java:6856)  
    at java.lang.reflect.Method.invoke(Native Method)  
    at java.lang.reflect.Method.invoke(Method.java:372)  
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)  
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)  
    Caused by: 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:184) 
    at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:178) 
    at java.lang.reflect.Constructor.newInstance(Native Method)  
    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)  
    at android.view.LayoutInflater.createView(LayoutInflater.java:614)  
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)  
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:904)  
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)  
    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)  
    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)  
    at android.view.LayoutInflater.inflate(LayoutInflater.java:366)  
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)  
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)  
    at assetviewer.findergpstracking.com.finder.activity.HomeActivity.onCreate(HomeActivity.java:152)  
    at android.app.Activity.performCreate(Activity.java:6550)  
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)  
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3077)  
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3233)  
    at android.app.ActivityThread.access$1000(ActivityThread.java:197)  
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)  
    at android.os.Handler.dispatchMessage(Handler.java:102)  
    at android.os.Looper.loop(Looper.java:145)  
    at android.app.ActivityThread.main(ActivityThread.java:6856)  
    at java.lang.reflect.Method.invoke(Native Method)  
    at java.lang.reflect.Method.invoke(Method.java:372)  
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)  
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)  

這是我的風格主題

<resources> 

<style name="Theme.Findertheme" parent="@style/AppTheme"> 
    <item name="actionBarItemBackground">@drawable/selectable_background_findertheme</item> 
    <item name="popupMenuStyle">@style/PopupMenu.Findertheme</item> 
    <item name="dropDownListViewStyle">@style/DropDownListView.Findertheme</item> 
    <item name="actionBarTabStyle">@style/ActionBarTabStyle.Findertheme</item> 
    <item name="actionDropDownStyle">@style/DropDownNav.Findertheme</item> 
    <item name="actionBarStyle">@style/ActionBar.Transparent.Findertheme</item> 
    <item name="actionModeBackground">@drawable/cab_background_top_findertheme</item> 
    <item name="actionModeSplitBackground">@drawable/cab_background_bottom_findertheme</item> 
    <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Findertheme</item> 

    <item name="windowNoTitle">true</item> 
    <item name="windowActionBar">false</item> 
</style> 

<style name="ActionBar.Solid.Findertheme" parent="@style/Widget.AppCompat.ActionBar.Solid"> 
    <item name="background">@drawable/ab_solid_findertheme</item> 
    <item name="backgroundStacked">@drawable/ab_stacked_solid_findertheme</item> 
    <item name="backgroundSplit">@drawable/ab_bottom_solid_findertheme</item> 
    <item name="progressBarStyle">@style/ProgressBar.Findertheme</item> 
</style> 

<style name="ActionBar.Transparent.Findertheme" parent="@style/Widget.AppCompat.ActionBar"> 
    <item name="background">@drawable/ab_transparent_findertheme</item> 
    <item name="progressBarStyle">@style/ProgressBar.Findertheme</item> 
</style> 

<style name="PopupMenu.Findertheme" parent="@style/Widget.AppCompat.PopupMenu"> 
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_findertheme</item> 
</style> 

<style name="DropDownListView.Findertheme" parent="@style/Widget.AppCompat.ListView.DropDown"> 
    <item name="android:listSelector">@drawable/selectable_background_findertheme</item> 
</style> 

<style name="ActionBarTabStyle.Findertheme" parent="@style/Widget.AppCompat.ActionBar.TabView"> 
    <item name="android:background">@drawable/tab_indicator_ab_findertheme</item> 
</style> 

<style name="DropDownNav.Findertheme" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar"> 
    <item name="android:background">@drawable/spinner_background_ab_findertheme</item> 
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_findertheme</item> 
    <item name="android:dropDownSelector">@drawable/selectable_background_findertheme</item> 
</style> 

<style name="ProgressBar.Findertheme" parent="@style/Widget.AppCompat.ProgressBar.Horizontal"> 
    <item name="android:progressDrawable">@drawable/progress_horizontal_findertheme</item> 
</style> 

<style name="ActionButton.CloseMode.Findertheme" parent="@style/Widget.AppCompat.ActionButton.CloseMode"> 
    <item name="android:background">@drawable/btn_cab_done_findertheme</item> 
</style> 

<!-- this style is only referenced in a Light.DarkActionBar based theme --> 
<style name="Theme.Findertheme.Widget" parent="@style/Theme.AppCompat"> 
    <item name="popupMenuStyle">@style/PopupMenu.Findertheme</item> 
    <item name="dropDownListViewStyle">@style/DropDownListView.Findertheme</item> 
</style> 

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 

    <style name="AppTheme" parent="android:Theme.Holo"> 
     <item name="android:editTextBackground">@drawable/apptheme_edit_text_holo_dark</item> 
     <item name="android:listChoiceIndicatorMultiple">@drawable/apptheme_btn_check_holo_dark</item> 
     <item name="android:buttonStyle">@style/ButtonAppTheme</item> 
     <item name="android:imageButtonStyle">@style/ImageButtonAppTheme</item> 
     <item name="android:dropDownSpinnerStyle">@style/SpinnerAppTheme</item> 
     <item name="android:progressBarStyleHorizontal">@style/ProgressBarAppTheme</item> 
     <item name="android:seekBarStyle">@style/SeekBarAppTheme</item> 
     <item name="android:listChoiceBackgroundIndicator">@drawable/apptheme_list_selector_holo_dark</item> 
     <item name="android:activatedBackgroundIndicator">@drawable/apptheme_activated_background_holo_dark</item> 
    </style> 

</resources> 

誰能告訴我這裏有什麼實際問題? 請建議我可能的解決方案。

+0

你似乎已經切斷logcat的。請提供更多 –

+0

@ cricket_007請參閱。我添加了完整的logcat。 – anuradha

+0

'由於:java.lang.IllegalArgumentException:您需要使用Theme.AppCompat主題(或後代)與設計庫' –

回答

0

HomeActivity exnteds AppCompatActivity,所以AppTheme應該繼承Theme.AppCompat

https://developer.android.com/reference/android/support/v7/app/AppCompatActivity.html

設置活動主題Theme.AppCompat或一個相似的主題。

您是否在Android Holo顏色生成器中選擇了「APPCOMPAT」兼容性?

enter image description here

+0

起初我沒有選擇AppCompact主題作爲compitability,因爲我的minmum sdk是15.但是在選擇AppCompact的主題compitability之後,我的問題就解決了。謝謝你的幫助。 – anuradha