Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 551
Kareem Essam Gaber Avatar asked Dec 25 '14 00:12

Kareem Essam Gaber


People also ask

How do I change the title text bar in Android?

First, add a font file in the src/main/assets/fonts/ of your project. Then create variables for Toolbar and text title and call the method findViewById(). Create a new Typeface from the specified font data. And at last setTypeface in text title.


1 Answers

getSupportActionBar().setDisplayShowTitleEnabled(true); 
like image 101
massaimara98 Avatar answered Oct 14 '22 00:10

massaimara98