android中的自定义主题设计问题

时间:2016-07-22 14:59:42

标签: android

我正在使用Custom Action BarAndroid Holo Colors Generator为我的Android应用实现主题设计。动作栏样式工作正常。但是使用Android Holo Colors Generator实现自定义主题时会出现问题。错误是

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>

谁能告诉我这里的实际问题是什么? 请建议我可能的解决方案。

1 个答案:

答案 0 :(得分:0)

您的HomeActivity已放逐AppCompatActivity,因此AppTheme应继承Theme.AppCompat

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

  

将活动主题设置为Theme.AppCompat或类似主题。

您是否在Android Holo Colors Generator中选择了“APPCOMPAT”兼容性?

enter image description here