Kareem Essam Gaber Kareem Essam Gaber - 3 months ago 15
Android Question

android title won't show in toolbar

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 handel 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
getSupportActionBar().setDisplayShowTitleEnabled(true);