What causes android exception “You need to use a Theme.AppCompat theme (or descendant) with this activity.”

后端 未结 2 2025
夕颜
夕颜 2021-01-14 18:32

I am attempting to try out the new Material Theme in Android.

I am currently stuck with this exception

03-06 09:35:50.177: D/AndroidRuntime(30607): S         


        
相关标签:
2条回答
  • 2021-01-14 18:54

    If you're using ActionBarActivity then you need to use the ThemeCompat styles. You can only use Theme.Material if you use "Activity" instead.

    You CAN still use API 21 items like tinting and elevation natively, but in order to use the native material theme you must use the Activity class.

    You can still use a Material UI style while using the AppCompat libraries, however: http://android-developers.blogspot.co.uk/2014/10/appcompat-v21-material-design-for-pre.html

    0 讨论(0)
  • 2021-01-14 19:12

    You are attempting to use a feature (from the design library, for example) which was introduced after your target sdk. Therefore, you need to use a couple of libraries (design and appcompat), one of which is the AppCompat Theme (backwards app compatibility).

    In your Manifest file, include in your application declaration

    android:theme="@style/Theme.AppCompat"
    

    Rebuild and your problem should be solved.

    0 讨论(0)
提交回复
热议问题