Here is an image of my custom action bar:
I want to use the entire wid
I just wanted to tell everybody that IN SOME WAY having this code below does not work. A space between the edge of the screen and the Toolbar remains in my case.
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
I spent ~2hours doing some manipulations with styles and this two attributes. Nothing helped me. All of a sudden I thought whether this "space" may be just a padding or margin of the Toolbar. But my Toolbar hadn't had any padding or margin. And I added 0dp
padding to the Toolbar
in my layout .xml file.
android:padding="0dp"
It worked. You can imagine my face. This space has gone away. Android lied to me.
Read this link1, link2 and set the contentInsets to 0dp like done below:
View mCustomView = mInflater.inflate(R.layout.actionbar_invoice, null);
getSupportActionBar().setCustomView(mCustomView);
Toolbar toolbar=(Toolbar)mCustomView.getParent();
toolbar.setContentInsetsAbsolute(0,0);
If you are using custom Toolbar instead of ActionBar then use below code:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="@dimen/action_bar_height"
android:background="?attr/colorPrimary"
android:contentInsetStart="0dp"//see this
android:contentInsetLeft="0dp"//see this
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
I Hope this might help you.
I solved this by using toolbar and adding the following properties to this.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:id="@+id/toolbar_blurrbg"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/toolbar_bg"
android:visibility="gone" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/actionbar_bg"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp" />
app:contentInsetEnd and app:contentInsetStart ..
See if it helps you
Follow few simple steps. 1. Make your own custom Action view action_view.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="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:id="@+id/bar_title1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/White"
android:text="title1"/>
<TextView
android:id="@+id/bar_title2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/White"
android:text="title2"/>
<TextView
android:id="@+id/bar_title3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/White"
android:text="title3"/>
</LinearLayout>
Here is the code:
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.custom_action_bar, null);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
This will surely solve your purpose. Happy Coding !!!
ActionBar action = getSupportActionBar();
action.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
Toolbar toolbar=(Toolbar)action.getCustomView().getParent();
toolbar.setContentInsetsAbsolute(0, 0);
toolbar.getContentInsetEnd();
toolbar.setPadding(0, 0, 0, 0);