Pochmurnik
Pochmurnik

Reputation: 828

Setting default theme

I started using Android Studio and I noticed that there was default theme Material Dark -> Material.

Some time later, after creating new project all Views disappeared from preview. I didn't know why, but finally I discovered that Theme changed to AppTheme.

And now I would like to set default Theme again to material. I see no option for that. A lot of google links direct me to set IDE Theme to IntelliJ or Darcula (this is not what I want to do).

In AndroidManifest.xml I can't get Material after writing Theme(dot)

    <style name="AppTheme" parent="Theme.Material.Light.DarkActionBar">

minSdkVersion is set to 15, compileSdkVersion to 28.

Edit1: Everytime I add another view in Text mode, Theme changes to AppTheme. And then I see nothing on preview until I change Theme on Material.

How to set default Material Dark -> Material for my app projects?

Upvotes: 1

Views: 2829

Answers (1)

Martin
Martin

Reputation: 650

You need to define activity theme in Manifest. If you want to change theme for specific activity edit activity declaration like this:

<activity
    android:name=".MainActivity"
    android:theme="@style/AppTheme">
</activity>

where AppTheme is your theme defined in styles.xml

If you want to set default theme for all activities, add android:theme to Application tag

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

where AppTheme is your theme from styles.xml.

These attributes will force preview to load your theme anytime.

Note: You should use Theme.AppCompat because of compatibility.

EDIT: I didn't read your question carefully. In manifest you can use android:theme="@android:style/Theme.Material" for material theme. Or better, for compatibility, android:theme="@style/Theme.AppCompat".

Upvotes: 2

Related Questions