I want to add a save button
in action bar but it shows below the action bar
.
What is the correct to solve ? Any help would be greatly appreciated.
Code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black"
android:theme="@style/Theme.AppCompat"
android:minHeight="?attr/actionBarSize">
<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_height="match_parent">
<Button
android:id="@+id/save"
android:text="SAVE"
android:layout_width="wrap_content"
android:background="#000"
android:textColor="#fff"
android:layout_height="wrap_content"
android:textSize="16dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_marginLeft="50dp"
android:layout_marginTop="20dp"
android:background = "@drawable/img_receipt"
android:src="@drawable/upload"
android:scaleType="fitXY"
android:layout_width="270dp"
android:layout_height="290dp"
android:id="@+id/image" />
<TextView
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Add a description"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_marginTop="40dp"
android:id="@+id/textView"
android:layout_below="@+id/image"
/>
<EditText
android:layout_marginLeft="5dp"
android:layout_width="350dp"
android:paddingBottom="75dp"
android:paddingLeft="10dp"
android:layout_height="120dp"
android:hint="Add a description"
android:textColor="@color/black"
android:background="@drawable/roundedcorner_edittext"
android:layout_marginTop="80dp"
android:layout_below="@+id/image"
android:id="@+id/editText" />
</RelativeLayout>
Screen Shot
As you can see the save button is placed below action bar. I want it place beside the healthy app title.
You can add button on action bar like that...
Remove toolbar(if you are using only to add save button on action bar)
create the menu_main xml file:
Then in your activity, if you created a new file your need to edit onCreateOptionsMenu
and you can edit what the actions do in the following method:
Hope this will help you.
Finally I get it works
In my Receipt Activity, add these two lines
and add this lines in androidMainFest to avoid the app cras