Android Change Activity Title

Jun 18, 2018
Why Android Activity Title Doesn't Change?

Activity's title is usually set at AndroidManifest.xml using android:label.

<activity
    android:name=".view.TestActivity"
    android:label="@string/title_activity_test" />

You can also call Activity.setTitle programatically.

class TestActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)        setContentView(R.layout.activity_test)        setSupportActionBar(toolbar)        setTitle("My Title")    }}

Once I found that I fail to change activity title using the above methods. Eventually I found out the layout xml generated by Android Studio assign a title to toolbar. Solution: Remove app:title from Toolbar.

<android.support.design.widget.CoordinatorLayout ...>

    <android.support.design.widget.AppBarLayout ...>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:title="@string/app_name"
            >

    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>  

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.