I'm using a toolbar which works pretty well for the most part until I started adding widgets inside it. I have a checkbox and button declared inside the toolbar but would like them to appear at the far end of the toolbar and working towards the title. I.e. the title remains on the left starting from the margin, but icons are added from the right. how do I go about this? I tried changing layout direction, but it just appeared Arabic like..
Asked
Active
Viewed 621 times
2 Answers
0
You can use RelativeLayout as a child layout in toolbar and add icons in it then you can give alignment(left,right etc) to those icons

Akshay Panchal
- 695
- 5
- 15
0
As you have not shown your code, supposing that your toolbar.xml is somewhat like this.
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/accent_color"
android:minHeight="?attr/actionBarSize"
android:layout_alignParentTop="true"
tools:context=".MyActivity"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/save"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="right" //might be the missing part
android:textColor="@color/white"
android:text="SAVE"/>
</android.support.v7.widget.Toolbar>
all you have to do is add gravity
android:layout_gravity="right"

Rishabh Lashkari
- 638
- 1
- 8
- 22
-
1amazing solution. simple but elegant. I'm a little surprised Android studio does not give hints for any of those properties in the toolbar tag – jaletechs Jul 01 '16 at 11:16