Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 4 ion-title in toolbar is not centered on android

I am wondering if this a common problem. My ion-title is not centered in the toolbar on android.

I googled it but I couldn't find anything for ionic 4, what I did found was a pretty good solution in ionic 3.

here it is: https://stackoverflow.com/a/30021395/4983589

I am wondering if somebody know how to do this in ionic4?

Here an image how it looks on android:

enter image description here

like image 287
Sireini Avatar asked Feb 08 '19 18:02

Sireini


People also ask

How do I center ion title in ion toolbar?

To use a particular behavior you can use mode="md|ios" . md is for android and ios for IOS devices. Since you want to make the title on center, you can use mode="ios" which will make the toolbar title to be on center for both android and ios devices.

How do you change the color of an ion title?

You can change the background color of the toolbar with the standard title by setting the --background CSS variable on ion-toolbar . This will give the effect of the header changing color as you collapse the large title.

What is ionic toolbar?

The toolbar is a generic bar which is used in an app as a header, sub-header, footer, or sub-footer. It is positioned above or below the content. You can add more than one toolbar in your page, and the <ion-content> will adjust it accordingly.


3 Answers

Ionic v4 keeps toolbar title on left for android devices and on center for IOS devices.

To use a particular behavior you can use mode="md|ios". md is for android and ios for IOS devices.

Since you want to make the title on center, you can use mode="ios" which will make the toolbar title to be on center for both android and ios devices.

This is my header:

<ion-header>
    <ion-toolbar mode="ios">
        <ion-title>
            Add New Rest
        </ion-title>
        <ion-icon slot="end" name="analytics"></ion-icon>
        <ion-buttons slot="start">
            <ion-buttons slot="start">
                <ion-back-button defaultHref="home"></ion-back-button>
            </ion-buttons>
        </ion-buttons>
    </ion-toolbar>
</ion-header>

Have a look at the screenshot below enter image description here enter image description here

like image 70
Varun Sukheja Avatar answered Oct 20 '22 08:10

Varun Sukheja


I have tested the followings on my android and the title is centered with other buttons such as back button, etc.

Not too sure if it works on iOS devices
Hopefully this helps:

<ion-toolbar>
    <ion-title style="width: 100%; position: absolute; left: 0; height: 0;">
        Title
    </ion-title>
</ion-toolbar>
like image 40
samheihey Avatar answered Oct 20 '22 07:10

samheihey


Adding mode="ios" does work. To simplify you can add mode="ios" to the main HTML tag in the index.html and this will be applied to the entire app so you don't have to add this to each individual HTML page.

like image 2
Meraiah Avatar answered Oct 20 '22 08:10

Meraiah