First, I created two styles, one is value and the other is value-21.
In values/styles.xml is
<resources>
<style name="AppTheme" parent="Theme.AppCompat"></style>
</resources>
In values-v21/styles.xml is
<resources>
<style name="AppTheme" parent="android:Theme.Material"></style>
</resources>
My gradle file (app.gradle)

Since the ActionBarActivity is deprecated, so I use AppCompatActivity.
When I set these two style values and extend AppCompatActivity in MainActivity, I got the exception:
java.lang.IllegalStateException: You need to use a Theme.AppCompat
theme (or descendant) with this activity.
I do the two different changes and that exception never shows up again:
Should I extend the "android.app.Activity" if I want to use the design theme?
Or, is there another way to use material design theme?
Thanks.
Write the below theme in your style.xml file.
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">any_color_code</item>
<item name="colorPrimaryDark">any_color_codek</item>
<item name="colorAccent">any_color_code</item>
</style>
and write extends AppCompatActivity in your `MainActivity
and in the Manifest.xml file write your application tag as below:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
</application>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With