Reputation: 1496
Maybe this is well known option in Android Studio but I couldn't find it and Google has not helped me with this :( Every time I open a layout preview in Android Studio it's applying Material.Light theme to every layout in my project and I need manually apply my own theme to see how it will look like in a real app. Does somebody know how to change default Material.Light theme to be my custom theme when previewing layout with Layout Previewer in Android Studio so I don't need to apply it manually every time?
Thanks in advance.
Upvotes: 44
Views: 14101
Reputation: 11
If you want that android studio should always show the a particular theme for layout previews then in the XML file for that layout you can add tools:theme="@style/Theme.App"
This will only apply this theme for development viewing purposes automatically when a layout file is opened. So that you dont need to set the theme from, lets say starting splashsrceen theme (Theme.Starting
) to actual app theme (Theme.App
)
Note: You need to add this to all your required layout XML files where you want Theme.App
to be shown for XML layout file preview.
example code:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:theme="@style/Theme.App">
Upvotes: 1
Reputation: 32221
Found a solution!
It must be set in the manifest, but wait there is a workaround. Use tools, then it will only effect the default theme in Android Studio Layout Preview
<application tools:theme="@style/RetailTheme">
Upvotes: 0
Reputation: 2014
In all your manifests (in all modules), set
<application android:theme="@Theme/mainTheme">
</application
If you use Splashscreen theme (official way)
in your App module,
<application
android:theme="@style/SplashTheme"
tools:replace="android:theme">
</application>
AND RESTART Android Studio (very important)
Upvotes: 4
Reputation: 101
You need to provide default theme on application tag in AndroidManifest.xml
file. If you don't provide android:theme="@style/{themeName}
there will be added Material.Light
default theme.
Please check example of code snippet from my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage.iqall" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/iqall_main"
android:label="@string/app_name"
android:logo="@drawable/logo"
android:theme="@style/AppTheme" <!--in Preview you will see this as default preview-->
android:name=".IQallApp">
</application>
</manifest>
Upvotes: 6
Reputation: 672
Click here and change theme to your theme.
If you want a single theme to always open, give
android:theme="@style/YourTheme"
in your <application>
tag in Manifest file.
From next time onwards, when you create a new xml file, this will be your default theme.
Upvotes: 8