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:



enter image description here



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?










share|improve this question






















  • 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















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:



enter image description here



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?










share|improve this question






















  • 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













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:



enter image description here



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?










share|improve this question













I'm trying to add a toolbar inside a constraint layout but this is the result I'm getting:



enter image description here



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












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>





share|improve this answer





















  • 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




















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.






share|improve this answer























  • This didn't change anything.
    – Marco Ripamonti
    2 days ago


















up vote
0
down vote













I solved this issue by putting the action bar on the main activity instead of the fragment layout.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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>





    share|improve this answer





















    • 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

















    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>





    share|improve this answer





















    • 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















    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>





    share|improve this answer












    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>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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




















    • 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














    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.






    share|improve this answer























    • This didn't change anything.
      – Marco Ripamonti
      2 days ago















    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.






    share|improve this answer























    • This didn't change anything.
      – Marco Ripamonti
      2 days ago













    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.






    share|improve this answer














    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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 2 days ago

























    answered 2 days ago









    Lucefer

    9661511




    9661511












    • 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




    This didn't change anything.
    – Marco Ripamonti
    2 days ago










    up vote
    0
    down vote













    I solved this issue by putting the action bar on the main activity instead of the fragment layout.






    share|improve this answer

























      up vote
      0
      down vote













      I solved this issue by putting the action bar on the main activity instead of the fragment layout.






      share|improve this answer























        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.






        share|improve this answer












        I solved this issue by putting the action bar on the main activity instead of the fragment layout.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Marco Ripamonti

        166




        166






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin