也许这是 Android Studio 中众所周知的选项,但我找不到它,谷歌也没有帮助我 :( 每次我在 Android Studio 中打开布局预览时,它会将 Material.Light 主题应用于项目中的每个布局,我需要手动应用自己的主题才能看到它在真实应用程序中的效果。有人知道如何将默认的 Material.Light 主题更改为我的自定义主题,并在使用 Layout Previewer 预览布局时进行设置,这样我就不必每次都手动应用了吗?
先感谢你们的帮助。
先感谢你们的帮助。
AndroidManifest.xml
文件的应用程序标签中,您需要提供默认主题。如果您不提供 android:theme="@style/{themeName}
,则会添加 Material.Light
默认主题。<?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>
<application android:theme="@Theme/mainTheme">
</application
<application
android:theme="@style/SplashTheme"
tools:replace="android:theme">
</application>
并重新启动 Android Studio(非常重要)
tools:theme="@style/Theme.App"
。Theme.Starting
)设置为实际应用程序主题(Theme.App
)。Theme.App
的布局XML文件中。<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">
找到解决方案了!
必须在清单文件中进行设置,但是等等,有一个变通方法。使用工具,然后它只会影响Android Studio布局预览中的默认主题。
<application tools:theme="@style/RetailTheme">