javaandroidxmllabelvisible

Why are activity labels showing / not showing in android studio


For some reason, my TaskForm.java activity is showing the value of @strings/app_name as it's label. I can't get it to stop showing the label, nor can I get any of my other activities to show the label so I would like to fix this inconsistency. I have looked through my androidManifest.xml, and compared my task_form.xml with other .xmls, and I have no idea what could be causing this. Apologies if this is a simple mistake, I am a beginner in android studio and I have tried to find a solution, any help would be greatly appreciated.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.C20487654_Assignment"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTask"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>

        <activity android:name=".NewActivity">
        </activity>

        <activity android:name=".TaskForm">
        </activity>

        <service
            android:name=".NotificationService"
            android:label="@string/app_name"
            android:exported="true">
            <intent-filter>
                <action android:name="your.app.domain.NotificationService" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </service>

    </application>

</manifest>

task_form.xml (shows label)

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <EditText
            android:id="@+id/idEdtTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:hint="Enter Title" />

        <EditText
            android:id="@+id/idEdtTask"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:hint="Enter Task" />

        <Button
            android:id="@+id/addTaskBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="Add Task"
            android:textAllCaps="false" />

        <Button
            android:id="@+id/cancelTaskBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="Cancel"
            android:textAllCaps="false" />

    </LinearLayout>

new_screen.xml (doesn't show label)

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="15dp"
    android:paddingBottom="15dp"
    android:orientation="vertical">

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:paddingBottom="10dp"
        android:orientation="horizontal">

        <TextView android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:paddingLeft="15dp"
            android:text="Name: "
            android:textSize="20sp"/>

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textSize="20sp"
            android:textColor="@color/black"
            android:id="@+id/name"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="30dp"
            android:text="Status: "
            android:textSize="20sp" />


        <TextView
            android:id="@+id/status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textSize="20sp" />

    </LinearLayout>

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:paddingLeft="15dp"
            android:text="Description: "
            android:textSize="20sp"/>

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:paddingBottom="15dp"
            android:textSize="20sp"
            android:textColor="@color/black"
            android:id="@+id/description"/>

    </LinearLayout>

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:orientation="horizontal">

        <Button
            android:id="@+id/completeBtn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Complete"
            android:visibility="visible"
            android:backgroundTint="@color/green"/>

        <Button
            android:id="@+id/removeBtn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Remove"
            android:visibility="visible"
            android:backgroundTint="@color/red"/>

    </LinearLayout>

    <Button
        android:id="@+id/cancelBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Cancel" />


</LinearLayout>

Solution

  • I eventually realized that one of the classes was extending Activity and all of the others were extending AppCompatActivity which was causing the difference in style.