You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android设备Toolbar显示异常求助:AVD与布局编辑器效果不符

Hey there, let's figure out why your Toolbar works perfectly in the layout editor but doesn't match on the AVD. Looking through your code, I've spotted a couple of critical issues causing this mismatch:

1. Your AndroidManifest.xml has the wrong content

You accidentally pasted the activity_main.xml layout code into your AndroidManifest.xml — that's a big problem! The manifest file defines your app's core structure and components, not UI layouts.

Here's what a correct basic AndroidManifest.xml should look like (update the package name and theme to match your project):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        <!-- Critical: Use a theme without a default ActionBar -->
        android:theme="@style/Theme.MyApplication">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

2. Your app theme must disable the default ActionBar

If your app's theme includes a built-in ActionBar, it will conflict with your custom Toolbar — this is the most common reason for the layout editor vs AVD discrepancy.

Open res/values/styles.xml and ensure your theme inherits from a NoActionBar variant:

<resources>
    <!-- Base application theme -->
    <style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <!-- Primary brand color -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Optional: Match status bar color to your Toolbar -->
        <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
    </style>
</resources>

Your menu file is named style.xml — this is confusing because it clashes with the app's styles file. Rename it to something like menu_main.xml and update the reference in activity_main.xml:

app:menu="@menu/menu_main"

Quick fix checklist:

  • Replace your broken AndroidManifest.xml with the correct structure above
  • Switch to a NoActionBar theme in your styles and manifest
  • Rebuild your project (not just run) to apply all changes

After making these adjustments, run your app on the AVD again — your custom Toolbar should now look exactly like what you see in the layout editor!

内容的提问来源于stack exchange,提问作者AdorableParker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:00:08