Left to right alignment in Toolbar Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Left to right alignment in Toolbar without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have a toolbar and i want to align the text to left instead of right.

The Main.xml file code is:

 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include
            android:id="@+id/main_page_toolbar"
            layout="@layout/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >
        </include>

The code of app_bar_layout.xml is:

   <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/grey_border_bottom"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:titleTextColor="@color/link_blue">

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

And the relevant code in Main java file is:

  mToolbar = (Toolbar) findViewById(R.id.main_page_toolbar);
        setSupportActionBar(mToolbar);
        final String phoneLanguage = Locale.getDefault().toString();
        if (phoneLanguage.equals("iw_IL"))
        {
            getSupportActionBar().setTitle("פוליטיקה");
        }
        else
        {
            getSupportActionBar().setTitle("Politico");
        }

Answer

include Textview in your app_bar_layout.xml

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main_app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent" 
            android:textColor="#000000"
            android:text="@string/app_name"
            android:gravity="right"
            />
    </android.support.v7.widget.Toolbar>
We are here to answer your question about Left to right alignment in Toolbar - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji