【问题标题】:Android App - the toolbar goes away when I debug the app [duplicate]Android应用程序-当我调试应用程序时工具栏消失了[重复]
【发布时间】:2023-04-09 13:03:01
【问题描述】:

在 Android Studio 中,应用的显示效果如我所愿。虽然在调试应用程序时,显示应用程序名称的横幅会消失。

我在哪里出错了?

为了更清楚,下面是它在 Android Studio 上的显示方式:

这是我运行应用程序时的显示方式(您可以看到没有横幅)

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.it5.foothillers.MainActivity"
    android:background="#f4f4f4">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:weightSum="1"
        android:paddingEnd="0dp"
        android:paddingStart="0dp"
        android:layout_margin="0dp">

        <Button
            android:layout_width="fill_parent"
            android:layout_height="23dp"
            android:text="NEWS"
            android:id="@+id/button"
            android:layout_weight="0.28"
            android:background="@android:color/holo_blue_bright"
            android:textColor="#ffffff"
            android:textSize="48dp" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="SPORTS"
            android:id="@+id/button2"
            android:layout_weight="0.20"
            android:background="@android:color/holo_blue_light"
            android:textColor="#ffffff"
            android:textSize="48dp" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="24dp"
            android:text="EVENTS"
            android:id="@+id/button3"
            android:layout_weight="0.29"
            android:background="@android:color/holo_blue_dark"
            android:textColor="#ffffff"
            android:textSize="48dp" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="24dp"
            android:text="MORE"
            android:id="@+id/button4"
            android:layout_weight="0.24"
            android:background="#f1f108"
            android:textSize="48dp" />
    </LinearLayout>
</RelativeLayout>

【问题讨论】:

    标签: java android


    【解决方案1】:

    更新:

    如果您的应用扩展 Activity,请将 if 更改为 AppCompatActivity

    【讨论】:

    • 如果您查看该用户的older post,则主题似乎已被使用。
    • 谢谢,我猜他只需要AppCompatActivity..
    • 嘿,你是英雄!!!谢谢!!它起作用了:))@MounirElfassi
    • 不客气,很高兴为您提供帮助,现在您可以投票了,您有 20 分 hhh
    • 我投了赞成票!!!谢谢你,这是一个如此简单的修复。
    【解决方案2】:

    确保您的类扩展了 AppCompatActivity,如果您仍然看不到操作栏,请尝试将 AndroidManifest.xml 中的应用主题更改为 Theme.AppCompat.Light.DarkActionBar。

    您也可以尝试在 res 中的 styles.xml 中进行设置

    <item name="android:windowActionBar">false</item>
    

    希望对你有帮助!亲切的问候!

    【讨论】:

    • 通过将类扩展为AppCompatActivity来显示actionbar。有效!!!如此简单的修复@Isaac
    猜你喜欢
    • 2017-05-22
    • 2016-12-13
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多