android:Theme.Material.Light requires API level 21 (current min is 8)

前端 未结 4 1976
盖世英雄少女心
盖世英雄少女心 2021-01-31 15:04

I want to use Material Theme in my application which has minimum sdk version of 8. As per docs - \"The material theme is only available in Android 5.0 (API level 21) and above.

4条回答
  •  Happy的楠姐
    2021-01-31 15:41

    Pedro Oliveira is right with regards to Theme.AppCompat, but some essential information is missing in that answer.

    A blog post titled appcompat v21: material design for pre-Lollipop devices! by Chris Banes from the Android team probably best answers the question of how to get Material Theme for API levels prior to 21.

    To summarise, you need appcompat-v7 dependency:

    dependencies {
        ...
        compile "com.android.support:appcompat-v7:21.0.3"
    }
    

    After that, for dark version as your base theme, use:

    
    

    And for light version:

    
    

    And if you're new to AppCompat, there are things you need to know, such as:

    All of your Activities must extend from ActionBarActivity*. It extends from FragmentActivity from the v4 support library, so you can continue to use fragments.

    *NB: more recently, ActionBarActivity has been deprecated in favour of AppCompatActivity.

    But you really should read the whole Setup section of that blog post! (The information on Toolbar vs Action Bar, and some of the comments are also something you probably shouldn't miss.)

提交回复
热议问题