Android hamburger menu shouldn't have padding on the end right side - android

I'm having padding to the right side of my close button, how can I remove it?
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/white"
android:elevation="#dimen/elevation_default_top_app_bar">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentInsetStart="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp">
<ImageButton
android:id="#+id/buttonHamburger"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="#null"
android:scaleType="centerInside"
android:src="#drawable/ic_menu_black_24dp"/>
<Button
android:id="#+id/buttonClose"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
app:icon="#drawable/ic_close_black"
android:layout_gravity="end|center_vertical" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>

Related

Auto hide or show tool bar when scroll up android

I want hide tool bar when scroll up to hide and scroll down to show. using xml
app:layout_scrollFlags="scroll|enterAlways|snap"
in tool bar.
Please help me out what actually output i need. When scrolling to top toolbar must hide and show when scroll down.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="275dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/ivTop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/apple_1"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
android:contentInsetEnd="0dp"
android:contentInsetRight="0dp"
android:padding="5dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="#style/AppTheme.PopupOverlay">
<ImageView
android:id="#+id/ivBack"
android:layout_width="35dp"
android:layout_height="35dp"
android:src="#drawable/icon_back_custom"
android:tint="#color/colorPrimary" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="#android:color/transparent"
app:tabBackground="#android:color/transparent"
app:tabIndicatorColor="#android:color/black"
app:tabIndicatorHeight="2.50dp"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:tabMode="fixed"
app:tabPadding="0dp"
app:tabSelectedTextColor="#android:color/black"
app:tabTextColor="#android:color/holo_blue_dark" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:id="#+id/tvTitleTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start|center_vertical"
android:padding="10dp"
android:text="TabSelection"
android:textAlignment="viewStart"
android:textColor="#color/colorAccent"
android:textSize="20sp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
How can i achive this? I want hide tool bar when scroll up to hide and scroll down to show. Please help me out what actually output i need. When scrolling to top toolbar must hide and show when scroll down.
I found the solution:
just make your toolbar and imageView in Layout with app:layout_scrollFlags="scroll|enterAlways"
like this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
//ImageView
//Toolbar
</RelativeLayout>
Full code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="275dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<ImageView
android:id="#+id/ivTop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ic_search"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
android:contentInsetEnd="0dp"
android:contentInsetRight="0dp"
android:background="#color/blue_cerulean_"
android:padding="5dp"
app:popupTheme="#style/AppTheme.PopupOverlay">
<ImageView
android:id="#+id/ivBack"
android:layout_width="35dp"
android:layout_height="35dp"
android:src="#drawable/ic_search"
android:tint="#color/colorPrimary" />
</android.support.v7.widget.Toolbar>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="#android:color/transparent"
app:tabBackground="#android:color/transparent"
app:tabIndicatorColor="#android:color/black"
app:tabIndicatorHeight="2.50dp"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:tabMode="fixed"
app:tabPadding="0dp"
app:tabSelectedTextColor="#android:color/black"
app:tabTextColor="#android:color/holo_blue_dark" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:id="#+id/tvTitleTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start|center_vertical"
android:padding="10dp"
android:text="TabSelection"
android:textAlignment="viewStart"
android:textColor="#color/colorAccent"
android:textSize="20sp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

blank space left even after setting match_parent

i have created an Toolbar with navigation drawer and menu, now i'm trying to add a textView and edittext on the same toolbar and place them in the center, but the problem is when i add relative layout and set width as match parent, it leases some space on the left side and the items which are to be placed in the center are shifted right.
i've pasted the code below:-
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="H E A D"
android:textSize="30dp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:id="#+id/ToolbarTextView"
style="#style/Base.TextAppearance.AppCompat.Large"
android:layout_marginTop="9dp"
android:textColor="#color/colorwhite"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ToolbarTextView"
android:layout_centerHorizontal="true"
android:text="Tagline"
android:textSize="15dp"
android:textColor="#color/colorwhite"/>
<EditText
android:layout_width="292dp"
android:layout_height="wrap_content"
android:background="#drawable/main_search"
android:padding="7dp"
android:backgroundTint="#color/colorwhite"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:hint="Search..."
android:id="#+id/ToolbarSearch1"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar></android.support.design.widget.AppBarLayout><include layout="#layout/content_main" /><android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />
the xml code of the mainActivity:-
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.strease.user.strease.MainActivity"
android:id="#+id/layout4"
tools:showIn="#layout/app_bar_main">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:paddingTop="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/></android.support.constraint.ConstraintLayout>
the reference image is given below:-
Screenshot of the device is given below:-
P.S:- i need to omit the blank space and get the editText and textViews to the center of the layout(currently the are shifted towards right)
Navigation Drawer code in main Activity:-
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"><include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"/></android.support.v4.widget.DrawerLayout>
android:fitsSystemWindows="false"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
Try to add above four line in your toolbar. It will resolve your problem. And make your child layout inside width match_parent and height wrap_content. And set your sub child view alignment center to horizontally. It will resolve your problem.
If still not resolve your problem then update your XML file for your layout exactly with the included layout so we can find out what exactly problem going on with your layout.
You need to add this properties to Toolbar to remove that space.
android:contentInsetEnd="0dp"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:contentInsetStart="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
Like as below.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentInsetEnd="0dp"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:contentInsetStart="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
android:background="?attr/colorPrimary">
This will remove the default left space from Toolbar.
Here is screen shot. It seems Edit Text showing in exact center of Toolbar. Also update your minSdkVersion to 21 surely it will work.
Here is the layout code.
<android.support.design.widget.AppBarLayout 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="130dp"
android:background="#android:color/holo_red_light"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorAccent"
android:contentInsetEnd="0dp"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:contentInsetStart="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/ToolbarTextView"
style="#style/Base.TextAppearance.AppCompat.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="9dp"
android:text="H E A D"
android:textColor="#android:color/white"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ToolbarTextView"
android:layout_centerHorizontal="true"
android:text="Tagline"
android:textColor="#android:color/white"
android:textSize="15dp" />
<EditText
android:id="#+id/ToolbarSearch1"
android:layout_width="292dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:background="#android:color/white"
android:backgroundTint="#android:color/white"
android:hint="Search..."
android:padding="7dp" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />
</android.support.design.widget.AppBarLayout>
EDIT
Add another property to toolbar for Navigation Icon.
app:contentInsetStartWithNavigation="0dp"
Now your toolbar should be as below.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorAccent"
android:contentInsetEnd="0dp"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:contentInsetStart="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStartWithNavigation="0dp"
app:contentInsetStart="0dp">
EDIT 2
I have made some changes to your layout used Linear Layout instead of Relative Layout.
<android.support.design.widget.AppBarLayout 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="130dp"
android:background="#android:color/holo_red_light"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorAccent"
android:contentInsetEnd="0dp"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:contentInsetStart="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStartWithNavigation="0dp"
app:contentInsetStart="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/ToolbarTextView"
style="#style/Base.TextAppearance.AppCompat.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="H E A D"
android:textColor="#android:color/white"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tagline"
android:layout_marginTop="2dp"
android:textColor="#android:color/white"
android:textSize="15dp" />
<EditText
android:id="#+id/ToolbarSearch1"
android:layout_width="292dp"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:layout_marginTop="3dp"
android:backgroundTint="#android:color/white"
android:hint="Search..."
android:padding="7dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />
</android.support.design.widget.AppBarLayout>

How to pin tablayout on top while scrolling

i want to pin tab layout on top while scrolling and toolbar should hide. So I have achieved this using following code but problem is, when application start and activity created it works fine(pinned on top while scroll) but moving to another fragment and comeback it is not pinning on top it just scrolling like the toolbar. I am using this on fragment and parent home activity has noActionbar theme. Can anybody help?
Here is my xml file code:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
tools:context="com.plowns.droidapp.activites.HomeActivity">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/gradient_horizontal"
android:contentInsetEnd="0dp"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:contentInsetStart="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/rl_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:gravity="center_vertical">
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:elevation="8dp"
android:gravity="bottom"
app:tabGravity="fill"
app:tabIndicatorColor="#color/colorPrimary"
app:tabIndicatorHeight="3dp"
app:tabMode="scrollable"
app:tabSelectedTextColor="#color/white"
app:tabTextColor="#color/white" />
</android.support.design.widget.AppBarLayout>
you have to set the app:layout_collapseMode to pin in TabLayout.
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:elevation="8dp"
android:gravity="bottom"
app:tabGravity="fill"
app:tabIndicatorColor="#color/colorPrimary"
app:tabIndicatorHeight="3dp"
app:tabMode="scrollable"
app:tabSelectedTextColor="#color/white"
app:layout_collapseMode="pin"
app:tabTextColor="#color/white" />

How to achieve this type of toobar with search

I am creating a application where search box will be below of Toolbar and toolbar is scrollable . when Toolbar is not scrolled up EditText margin area will be primary color and when scrolled up margin area will be transparent ..
I am using this code..
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/myAppBar"
app:elevation="0dp"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:contentInsetStart="0dp"
app:popupTheme="#style/AppTheme.PopupOverlay">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:layout_marginTop="2dp"
android:textSize="10sp"
android:gravity="bottom"
android:text="Current location"/>
<TextView
android:id="#+id/current_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="13sp"
android:gravity="top"
android:text="Fetching \nCurrent Location"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="#color/white"
android:hint="Search Places"
android:textColorHint="#color/textColorSecondary"
android:drawablePadding="10dp"
android:drawableLeft="#drawable/search_black_24dp"
android:drawableStart="#drawable/search_black_24dp"
android:layout_margin="8dp"/>
</android.support.design.widget.AppBarLayout>
Expected Result
Actual Result
please use CollapsingToolbarLayout like below example :
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/appbar"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleEnabled="false"
app:layout_scrollFlags="scroll">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>

how to remove left margin of Android Toolbar?

I'm trying to use toolbar for my project.
Here is the code I am using:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:contentInsetLeft="0dp"
android:elevation="#dimen/margin_padding_8dp"
android:contentInsetStart="0dp">
<RelativeLayout
android:id="#+id/rlToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingRight="#dimen/margin_padding_16dp"
android:text="AppBar"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textColor="#color/white"
android:textSize="#dimen/text_size_20sp" />
</RelativeLayout>
I want to remove left margin, Here I set android:contentInsetLeft="0dp" and android:contentInsetStart="0dp" but it's not working..Please help me !
replace your xml with below xml
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="#dimen/margin_padding_8dp"
android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp">
<RelativeLayout
android:id="#+id/rlToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingRight="#dimen/margin_padding_16dp"
android:text="AppBar"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textColor="#color/white"
android:textSize="#dimen/text_size_20sp" />
</RelativeLayout>
Use app:contentInsetStart="0dp" to remove that left space.
See the below code and here I added app:contentInsetStart="0dp". You need to add that to your code because before API 21 (i.e. Lollipop) you need to add that line.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:contentInsetStart="0dp"
app:contentInsetStart="0dp"
>
</android.support.v7.widget.Toolbar>
Referring to #calvinfly comment:
I updated my code
<RelativeLayout
android:id="#+id/rlTop"
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="#android:color/white" >
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/titleString"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#468bac"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/rlStarsTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:layout_marginRight="2dp"
android:layout_toRightOf="#+id/toolbar_title"
android:layout_toEndOf="#+id/toolbar_title"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true">
<RatingBar
android:id="#+id/txtRatings"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="1dp"
android:gravity="center"
android:max="5"
android:rating="3.7"
android:textColor="#android:color/holo_blue_bright"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
Just add these two lines in your toolbar.xml
app:contentInsetStart="0dp"
app:contentInsetEnd="0dp"
This works for me...
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app2="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app2:contentInsetStart="0dp"/>
Add below xml code to your Toolbar !
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
Add following code to your .xml file It may solve. Perfectly working solution I have tried.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/white"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
app:theme="#style/toolbarPopup">
above 21 use following code
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primaryColor"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp" />
Use This Toolbar property for remove toolbar left space
app:contentInsetStart="0dp"
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:contentInsetStart="0dp">
</androidx.appcompat.widget.Toolbar>
Add below xml code to your Toolbar
<android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp">

Categories

Resources