i'm trying to center my a action bar text. I've linked the text to my styles.XML, and confirmed this works by changing the font color to red. But when i add android:gravity="center_horizontal", it doesnt seem to work.
My styles.xml code:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppThemeLight" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">15sp</item>
<item name="android:textStyle">italic</item>
<item name="android:layout_gravity">center_horizontal</item>
</style>
My mainactivity oncreate event:
setSupportActionBar(findViewById(R.id.tlb_roundedtoolbar))
My custom actionbar styling XML file:
[<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff" />
<corners android:radius="30dp" />
</shape>][1]
My mainactivity.XML
<androidx.appcompat.widget.Toolbar
android:id="@+id/tlb_roundedtoolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/tlb_roundedtoolbar"
android:elevation="4dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
app:titleTextColor="@android:color/holo_red_light"
app:titleTextAppearance="@style/Toolbar.TitleText"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintTop_toTopOf="parent"
/>
Here's the result i'm getting with this code: [1]: https://i.stack.imgur.com/HgFc8.png
UPDATE
I've tried placing the toolbar within a linear layout, as suggested in this post: How to center align the ActionBar title in Android?.
However, my current code is still giving me the same result as before, with the text allinging to the left.
Current code (mainactivity.xml):
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_gravity="center"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tlb_roundedtoolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/bcg_rounedrtoolbar"
android:elevation="4dp"
android:gravity="center"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:titleTextColor="@color/colorPrimaryDark" />
</LinearLayout>