I have a toolbar inside of an AppBarLayout like this:
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="horizontal">
<ImageButton
android:id="@+id/editButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="16dp"
android:scaleType="fitCenter"
android:background=
"?attr/selectableItemBackgroundBorderless"
android:contentDescription="Post"
android:src="@drawable/ic_mode_edit_24dp"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
In my Activity.OnCreate() I try to set the title like this:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Edit");
(Not sure if this matters but..) After that I inflate a fragment:
MyFragment fragment = new MyFragment();
fragment.setArguments(savedInstanceState);
// Add fragment with tag
getSupportFragmentManager().beginTransaction()
.add(R.id.content_frame, fragment, "my_frag")
.commit();
However, this has no effect. In fact, there is no title at all. Is this because I have a LinearLayout
inside of the Toolbar
or something? Or because of the AppBarLayout
?
LinearLayout
as a child of theToolbar
instead of using a menu? – Amalamalbena