Leebeedev
Leebeedev

Reputation: 2146

Custom view on a ToolBar v-21

I added a custom view on the toolbar using this

    toolbar = (Toolbar) findViewById(R.id.general_options_toolbar);
    setSupportActionBar(toolbar);
    actionBar = getSupportActionBar();
        LayoutInflater mInflater = LayoutInflater.from(this);
        View mCustomView = mInflater.inflate(R.layout.action_bar_title_main_ar, null);
        actionBar.setCustomView(mCustomView);
        actionBar.setDisplayShowCustomEnabled(true);

and it works fine. But the layout that I'm using it must show the the textView in it on the RIGHT, but actually it shows it on the left !!! How to make the text on the right side when the language is for example in Arabic ?? Here is the action_bar_title_main_ar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
    android:id="@+id/mytext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end"
    android:gravity="center_vertical"
    android:text="@string/preferences"
    android:textAllCaps="true"
    android:textColor="@color/orange"
    android:textSize="20sp" />

</LinearLayout>

Upvotes: 1

Views: 1151

Answers (1)

Leebeedev
Leebeedev

Reputation: 2146

I did it. Just I added a TextView inside my toolBar in the toolbar.xml layout and aligned the textView to be at the end like so:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<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/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    app:theme="@style/ThemeOverlay.AppCompat"
    app:popupTheme="@style/ThemeOverlay.AppCompat">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:gravity="center_vertical"
        android:text="@string/preferences"
        android:textAllCaps="true"
        android:textColor="@color/orange"
        android:textSize="20sp" />
</android.support.v7.widget.Toolbar>

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_below="@id/general_options_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

Upvotes: 2

Related Questions