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>