Blake Lassiter
Blake Lassiter

Reputation: 383

Set Title To Hidden on Android App

In my android app, I want to hide the app name from the view, as shown in the image on the left, but if you expand away, the app name to be displayed, as shown in the picture in the right. However, my current way to show the left image is to set android:label="@string/roster", which is incorrect.

The alternative is to completely hide the app name from all views. However, I struggled to do that and create the left image. I saw posts about using

android:theme="@android:style/Theme.NoTitleBar"

to remove titles, and I can do that, but then I couldn't display Roster in the red area. I can show more code on how my styles are set, if that is helpful.

Goal:

  1. App name = Attendance Tracker
  2. On Screen Activity = MainActivity (Roster is title)
  3. On view of Roster activity, app name is hidden, Roster is shown in toolbar
  4. On expanded view, app name is displayed as Attendance Tracker

AndroidMainfest.xml

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".list_items"
        android:label="@string/title_activity_list_items"
        android:theme="@style/AppTheme.NoActionBar">
    </activity>
    <activity android:name=".AddMember"
        android:label="@string/roster_add">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

android screen view Edit: I am aware the right picture displays different content, but the title bar is what I am focused on. I did not want to change the code of another page.

Upvotes: 0

Views: 353

Answers (2)

Faiz Malkani
Faiz Malkani

Reputation: 313

Simply calling the following method will hide the title from the toolbar

Assuming you're using the support library:

getSupportActionBar().setDisplayShowTitleEnabled(false);

Assuming you're using the system-provided toolbar:

getActionBar().setDisplayShowTitleEnabled(false);

Upvotes: 1

Nguyễn Trung Hiếu
Nguyễn Trung Hiếu

Reputation: 2032

Try this!!!

<activity android:name=".MainActivity"
    android:label="">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

Upvotes: 0

Related Questions