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?
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?
please set your layout and textview gravity to center if it is not working then try textview layoutGravity to center
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
you will try this in xml
android:layout_centerhorizontal="true"
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);
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
<?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>