0

I have to get this as a result:

Screenshot

Moreover, how do I add colour in the action bar's background?

Amos M. Carpenter
  • 4,848
  • 4
  • 42
  • 72

2 Answers2

0

Try this

Create toolbar.xml

 <?xml version="1.0" encoding="utf-8"?>
 <android.support.v7.widget.Toolbar
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="50dp"
  android:background="@color/orange"
  android:theme="@style/AppTheme.Toolbar.Theme"/>

Include this toolbar in your activitys xml file

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


<include
    android:id="@+id/tool_bar"
    layout="@layout/toolbar" />
</LinearLayout>

create your activity.java

public class MainActivity extends AppCompatActivity  {

protected ActionBar actionBar;
protected Toolbar toolbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_profile);
     toolbar = (Toolbar) findViewById(R.id.tool_bar);
     setSupportActionBar(toolbar);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
             finish(); //here add your back function code.
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
}
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
Jai Rajesh
  • 939
  • 5
  • 18
-1

Click here to add back action button in your actionbar and add onClick methocd for that button. For adding background to your actionbar refer this.

Hope this helps.

Community
  • 1
  • 1
Megha Maniar
  • 444
  • 5
  • 22