7

Can I center align the application name in android?

by default the application name is aligned in the left side.

so how to make it aligned center?

Freelancer
  • 836
  • 1
  • 14
  • 47
Strife
  • 101
  • 1
  • 1
  • 8

6 Answers6

2

please set your layout and textview gravity to center if it is not working then try textview layoutGravity to center

Rishi
  • 987
  • 6
  • 16
1

you will have to create a custom theme and set the style of window title to suit your needs.
This has some guideline http://labs.makemachine.net/2010/03/custom-android-window-title/

You could also use FEATURE_CUSTOM_TITLE and set format accordingly. This approach is detailed here.
How to change the text on the action bar

Community
  • 1
  • 1
nandeesh
  • 24,740
  • 6
  • 69
  • 79
1

you will try this in xml

android:layout_centerhorizontal="true"
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
0

To use a custom title in your Toolbar all you need to do is remember is that Toolbar is just a fancy ViewGroup so you can add a custom title like so:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_top"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/action_bar_bkgnd"
    app:theme="@style/ToolBarTheme" >


     <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Toolbar Title"
        android:layout_gravity="center"
        android:id="@+id/toolbar_title" />


    </android.support.v7.widget.Toolbar>

This means that you can style the TextView however you would like because it's just a regular TextView. So in your activity you can access the title like so:

Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);
soufianeios
  • 448
  • 5
  • 11
0

you have to change the theme in manifests its actually explained well in android developer website ... review this link https://developer.android.com/training/appbar/setting-up#java

0
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.google.android.material.appbar.MaterialToolbar
        android:id="@+id/topAppBar"
        style="@style/Widget.MaterialComponents.Toolbar.Primary"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:elevation="0dp"
        android:gravity="center"
        app:title="@string/app_name"
        app:titleCentered="true"
        android:contentDescription="@string/app_name"
        app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Earl89
  • 1