I found answer here : Android Lollipop, AppCompat ActionBar custom view doesn't take up whole screen width
I'm using Theme.AppCompat.Light.DarkActionBar
and setting custom layout in actionbar, But black area is displayed on the left side of actionbar.
This is the code of custom layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/color_red" >
<ImageView
android:id="@+id/actionbarBack_backButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/back_transparent_white"
android:padding="10dp"
android:src="@drawable/icon_back_white" />
<TextView
android:id="@+id/actionbarBack_title"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_marginLeft="5dp"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="Some text"
android:textColor="@android:color/white"
android:textSize="18sp" />
<View
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="10dp" />
</RelativeLayout>
This is the code, how I'm using in activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.actionbar_back_title);
actionBar.setDisplayShowCustomEnabled(true);
return super.onCreateOptionsMenu(menu);
}
onStart:
@Override
public void onStart(){
super.onStart();
ActionBar actionbar = getSupportActionBar();
actionbar.setDisplayHomeAsUpEnabled(false);
actionbar.setDisplayShowHomeEnabled(false);
actionbar.setHomeButtonEnabled(false);
}
Can anyone tell me what is the issue ?