android title won't show in toolbar

Kareem Essam Gaber picture Kareem Essam Gaber · Dec 25, 2014 · Viewed 32.5k times · Source

I have an xml that I use with so many activities with fragments file but my problem is that I can't display the text I want in the toolbar, I use that xml that way because I have a navigation drawer and I needed to handle somethings so I had to do it that way.

my xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".StatusActivity"
    android:orientation="vertical" >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        style="@style/ToolBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="@dimen/abc_action_bar_default_height_material" />

</RelativeLayout>

One of my activities:

public class GroupChatActivity extends ActionBarActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_layout);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
         getSupportActionBar().setDisplayShowHomeEnabled(true);

         ActionBar actionBar = getSupportActionBar();
         actionBar.setTitle("Groups history");

        Aniways.init(this);

        if(savedInstanceState == null)
        {
            FragmentManager manager = getSupportFragmentManager();

            Fragment fragment = GroupChatFragment.newInstance(getIntent().getIntExtra("uid", 0));
            manager.beginTransaction().add(R.id.frame_container, fragment).commit();
        }
    }
}

as you can see I try to set title to the action bar but it doesn't work.

Answer

massaimara98 picture massaimara98 · Dec 27, 2014
getSupportActionBar().setDisplayShowTitleEnabled(true);