3

I am using this theme in my Android app, Theme.AppCompat.Light.NoActionBar in every activity my project name i.e the label name from the Application tag appears in every Android activity, before it was not happening but recently it is happening. If I remove the label then the package name appears instead of the title.

What exactly is happening ?

I know that there are several ways to fix it but show me where I am wrong and what is happening ? Is it a bug ?

I referred a previous answer Android Application Name Appears as Activity Name and tried but still did not work, So here is a copy of my manifest.xml

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

Below is a sample screenshot, the label name can be seen although that activity(Activity2) consists of a toolbar , the white area is a edittext in the toolbar and nothing else is present inside the toolbar.

EDIT 1

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:textColorPrimary">@color/white</item>
        <item name="android:textColorSecondary">@color/white</item>
    </style>

EDIT 2

public class Activity2 extends AppCompatActivity {


    LinedEditText editText;
    Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity2);


        toolbar = (Toolbar) findViewById(R.id.toolbar);
        editText = (LinedEditText) findViewById(R.id.editText);
        setSupportActionBar(toolbar);


    }
}

activity2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
  >
    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/green"
        android:id="@+id/toolbar"
        >

        <EditText
            android:layout_width="250dp"
            android:layout_height="40dp"
           android:id="@+id/title"
            android:background="@color/white"
            android:layout_margin="10dp"
            />
        </android.support.v7.widget.Toolbar>
    <com.test.testproject.LinedEditText
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/editText"
        android:gravity="top"
        />
</LinearLayout>

enter image description here

oldcode
  • 1,669
  • 3
  • 22
  • 41

4 Answers4

0

UPDATE:

This is your problem. Avoid using Toolbar.

<android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/green"
        android:id="@+id/toolbar"
        >

        <EditText
            android:layout_width="250dp"
            android:layout_height="40dp"
           android:id="@+id/title"
            android:background="@color/white"
            android:layout_margin="10dp"
            />
        </android.support.v7.widget.Toolbar>

If you are using NoActionBar in your theme. Avoid using Toolbar in your Activity's layout. That is the reason you are getting the Activity name.

If you are using Toolbar make sure you disable the TITLE on it.

sagar suri
  • 4,351
  • 12
  • 59
  • 122
0

Check this out.

getSupportActionBar().setDisplayShowTitleEnabled(false);
Roma Darvish
  • 257
  • 5
  • 19
0
Check with setting theme for specific activity..which solves your problem..try this 
<style name = "NoActionBar" parent = "@android:style/Theme.Holo.Light">
        <item name = "android:windowActionBar">false</item>
        <item name = "android:windowNoTitle">true</item>
    </style>
0

Just put in onCreate() method after setSupportActionBar(toolbar).

    setContentView(R.layout.activity_main);
    ActionBar actionBar = getActionBar();
    actionBar.setTitle("");
Rajan1404930
  • 422
  • 5
  • 15