简体   繁体   English

XML 预览颜色与安卓实际app不同

[英]XML preview color is different from the actual app anddroid

I've created a project and added 2 buttons in activity_main.xml but they have different colors in layout preview and the actual app.我创建了一个项目并在 activity_main.xml 中添加了 2 个按钮,但它们在布局预览和实际应用程序中具有不同的 colors。 How come?怎么来的?

在此处输入图像描述

There are 2 files under themes:主题下有2个文件:

themes.xml:主题.xml:

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="NecklaceShowcase" parent="Theme.MaterialComponents.Light.NoActionBar" >
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>
</resources>

and themes.xml (night)和主题。xml(夜)

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="NecklaceShowcase">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_200</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/black</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_200</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>
</resources>

The layout preview is using the theme you have set in your themes.xml file.布局预览使用您在themes.xml 文件中设置的主题。

When you run the app the btn2 is switching to red because in your activity_main.xml it is setting its background to: halo_red_light .当您运行该应用程序时, btn2将切换为红色,因为在您的activity_main.xml中,它将其背景设置为: halo_red_light

I'm unable to tell why the other button is changed to grey this may have been set in your activity class.我不知道为什么另一个按钮变为灰色,这可能已在您的活动 class 中设置。

You can read more here你可以在这里阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 预览与实际屏幕不同 - Preview differs from actual screen 为什么设计(activity_main.xml)和实际应用看起来不同? - Why Design(activity_main.xml) and actual app look different? XML预览看起来与设备中的有所不同 - XML Preview looks different than in device 在我的设备上运行的应用程序与预览版不同 - The app that runs on my device is different to the preview 缩略图与gridview中的实际图像不同 - thumbnail different from actual image in gridview 模拟器中应用程序的设计与预览不同 - The design of the application in the emulator is different from the preview 与设备不同的 Android Studio 预览 - Android Studio preview different from device 错误:无法从C:\\ Users \\ JR的Computer \\ Desktop \\ COMT \\ Actual Cellar App \\ src \\ main \\ AndroidManifest.xml中读取packageName - Error:Cannot read packageName from C:\Users\JR's Computer\Desktop\COMT\Actual Cellar App\src\main\AndroidManifest.xml 如何修复 XML 中阻止在 Android Studio 上显示预览或运行应用程序的错误(红色文本)? - How can I fix errors (red texts) in XML which are preventing from showing preview or running the app on Android Studio? Netbeans GUI预览与运行时视图不同 - Netbeans GUI preview is different from Runtime view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM