Add toolbar in constraintLayout of a fragment layout
up vote
0
down vote
favorite
I'm trying to add a toolbar inside a constraint layout but this is the result I'm getting:
As you can see it doesn't fit the whole screen.
Here's my xml:
<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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment title"/>
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
The ConstraintLayout width and length are set to match parent (which should be the screen?) and the toolbar width is set to match the layout width.
What am I missing?
android xml layout toolbar android-constraintlayout
|
show 1 more comment
up vote
0
down vote
favorite
I'm trying to add a toolbar inside a constraint layout but this is the result I'm getting:
As you can see it doesn't fit the whole screen.
Here's my xml:
<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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment title"/>
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
The ConstraintLayout width and length are set to match parent (which should be the screen?) and the toolbar width is set to match the layout width.
What am I missing?
android xml layout toolbar android-constraintlayout
check answer of this stackoverflow.com/questions/53086154/…
– Lucefer
2 days ago
try to add custom toolbar ?
– Mitesh Vanaliya
2 days ago
toolbar autometically added in fragment if you are added custom view then create custom view file
– Mitesh Vanaliya
2 days ago
this is activity xml or fragment xml ?
– Mitesh Vanaliya
2 days ago
This is the layout of a fragment
– Marco Ripamonti
2 days ago
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to add a toolbar inside a constraint layout but this is the result I'm getting:
As you can see it doesn't fit the whole screen.
Here's my xml:
<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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment title"/>
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
The ConstraintLayout width and length are set to match parent (which should be the screen?) and the toolbar width is set to match the layout width.
What am I missing?
android xml layout toolbar android-constraintlayout
I'm trying to add a toolbar inside a constraint layout but this is the result I'm getting:
As you can see it doesn't fit the whole screen.
Here's my xml:
<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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment title"/>
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
The ConstraintLayout width and length are set to match parent (which should be the screen?) and the toolbar width is set to match the layout width.
What am I missing?
android xml layout toolbar android-constraintlayout
android xml layout toolbar android-constraintlayout
asked 2 days ago
Marco Ripamonti
166
166
check answer of this stackoverflow.com/questions/53086154/…
– Lucefer
2 days ago
try to add custom toolbar ?
– Mitesh Vanaliya
2 days ago
toolbar autometically added in fragment if you are added custom view then create custom view file
– Mitesh Vanaliya
2 days ago
this is activity xml or fragment xml ?
– Mitesh Vanaliya
2 days ago
This is the layout of a fragment
– Marco Ripamonti
2 days ago
|
show 1 more comment
check answer of this stackoverflow.com/questions/53086154/…
– Lucefer
2 days ago
try to add custom toolbar ?
– Mitesh Vanaliya
2 days ago
toolbar autometically added in fragment if you are added custom view then create custom view file
– Mitesh Vanaliya
2 days ago
this is activity xml or fragment xml ?
– Mitesh Vanaliya
2 days ago
This is the layout of a fragment
– Marco Ripamonti
2 days ago
check answer of this stackoverflow.com/questions/53086154/…
– Lucefer
2 days ago
check answer of this stackoverflow.com/questions/53086154/…
– Lucefer
2 days ago
try to add custom toolbar ?
– Mitesh Vanaliya
2 days ago
try to add custom toolbar ?
– Mitesh Vanaliya
2 days ago
toolbar autometically added in fragment if you are added custom view then create custom view file
– Mitesh Vanaliya
2 days ago
toolbar autometically added in fragment if you are added custom view then create custom view file
– Mitesh Vanaliya
2 days ago
this is activity xml or fragment xml ?
– Mitesh Vanaliya
2 days ago
this is activity xml or fragment xml ?
– Mitesh Vanaliya
2 days ago
This is the layout of a fragment
– Marco Ripamonti
2 days ago
This is the layout of a fragment
– Marco Ripamonti
2 days ago
|
show 1 more comment
3 Answers
3
active
oldest
votes
up vote
0
down vote
try this you have to set the constraintTop to the parent and also make width value match constraints and set start and end constraint to parent,
check the code below
<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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment title" />
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
This didn't help. Nothing changed.
– Marco Ripamonti
2 days ago
1
so if use fragment check if the frame layout or fragment view doesn't have any padding or margin on your activity XML
– Ahmed Wahdan
2 days ago
add a comment |
up vote
0
down vote
Try this out by adding these content inside 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"
I got this from Android: remove left margin from actionbar's custom layout. And u can try other solutions in there as well if this is not solve your problem.
This didn't change anything.
– Marco Ripamonti
2 days ago
add a comment |
up vote
0
down vote
I solved this issue by putting the action bar on the main activity instead of the fragment layout.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
try this you have to set the constraintTop to the parent and also make width value match constraints and set start and end constraint to parent,
check the code below
<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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment title" />
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
This didn't help. Nothing changed.
– Marco Ripamonti
2 days ago
1
so if use fragment check if the frame layout or fragment view doesn't have any padding or margin on your activity XML
– Ahmed Wahdan
2 days ago
add a comment |
up vote
0
down vote
try this you have to set the constraintTop to the parent and also make width value match constraints and set start and end constraint to parent,
check the code below
<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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment title" />
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
This didn't help. Nothing changed.
– Marco Ripamonti
2 days ago
1
so if use fragment check if the frame layout or fragment view doesn't have any padding or margin on your activity XML
– Ahmed Wahdan
2 days ago
add a comment |
up vote
0
down vote
up vote
0
down vote
try this you have to set the constraintTop to the parent and also make width value match constraints and set start and end constraint to parent,
check the code below
<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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment title" />
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
try this you have to set the constraintTop to the parent and also make width value match constraints and set start and end constraint to parent,
check the code below
<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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment title" />
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
answered 2 days ago
Ahmed Wahdan
6018
6018
This didn't help. Nothing changed.
– Marco Ripamonti
2 days ago
1
so if use fragment check if the frame layout or fragment view doesn't have any padding or margin on your activity XML
– Ahmed Wahdan
2 days ago
add a comment |
This didn't help. Nothing changed.
– Marco Ripamonti
2 days ago
1
so if use fragment check if the frame layout or fragment view doesn't have any padding or margin on your activity XML
– Ahmed Wahdan
2 days ago
This didn't help. Nothing changed.
– Marco Ripamonti
2 days ago
This didn't help. Nothing changed.
– Marco Ripamonti
2 days ago
1
1
so if use fragment check if the frame layout or fragment view doesn't have any padding or margin on your activity XML
– Ahmed Wahdan
2 days ago
so if use fragment check if the frame layout or fragment view doesn't have any padding or margin on your activity XML
– Ahmed Wahdan
2 days ago
add a comment |
up vote
0
down vote
Try this out by adding these content inside 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"
I got this from Android: remove left margin from actionbar's custom layout. And u can try other solutions in there as well if this is not solve your problem.
This didn't change anything.
– Marco Ripamonti
2 days ago
add a comment |
up vote
0
down vote
Try this out by adding these content inside 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"
I got this from Android: remove left margin from actionbar's custom layout. And u can try other solutions in there as well if this is not solve your problem.
This didn't change anything.
– Marco Ripamonti
2 days ago
add a comment |
up vote
0
down vote
up vote
0
down vote
Try this out by adding these content inside 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"
I got this from Android: remove left margin from actionbar's custom layout. And u can try other solutions in there as well if this is not solve your problem.
Try this out by adding these content inside 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"
I got this from Android: remove left margin from actionbar's custom layout. And u can try other solutions in there as well if this is not solve your problem.
edited 2 days ago
answered 2 days ago
Lucefer
9661511
9661511
This didn't change anything.
– Marco Ripamonti
2 days ago
add a comment |
This didn't change anything.
– Marco Ripamonti
2 days ago
This didn't change anything.
– Marco Ripamonti
2 days ago
This didn't change anything.
– Marco Ripamonti
2 days ago
add a comment |
up vote
0
down vote
I solved this issue by putting the action bar on the main activity instead of the fragment layout.
add a comment |
up vote
0
down vote
I solved this issue by putting the action bar on the main activity instead of the fragment layout.
add a comment |
up vote
0
down vote
up vote
0
down vote
I solved this issue by putting the action bar on the main activity instead of the fragment layout.
I solved this issue by putting the action bar on the main activity instead of the fragment layout.
answered 2 days ago
Marco Ripamonti
166
166
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350363%2fadd-toolbar-in-constraintlayout-of-a-fragment-layout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
check answer of this stackoverflow.com/questions/53086154/…
– Lucefer
2 days ago
try to add custom toolbar ?
– Mitesh Vanaliya
2 days ago
toolbar autometically added in fragment if you are added custom view then create custom view file
– Mitesh Vanaliya
2 days ago
this is activity xml or fragment xml ?
– Mitesh Vanaliya
2 days ago
This is the layout of a fragment
– Marco Ripamonti
2 days ago