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.
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.
getSupportActionBar().setDisplayShowTitleEnabled(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With