2

I want to make the label(My App) to be aligned centrally in action bar. How should I do?

Here is the current screen:

Home screen

ItsJ0el
  • 55
  • 1
  • 5
Eric
  • 303
  • 1
  • 8
  • 19

1 Answers1

10

If you are using Toolbar you might try this out :

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize">
 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="My App"
    android:layout_gravity="center"
    android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>

If you are using ActionBar try this :

In your onCreate() add this :

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
getSupportActionBar().setCustomView(R.layout.your_LAYOUT);

And your_LAYOUT should be like :

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="myApp"
    android:id="@+id/tvtitle" />

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148