Background overlapsing notification bar while using custom toolbar with AppBarLayout












0















I've created custom toolbar layout because I wanted to have a centered title on bar. The code looks like this:



main_activity.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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainactivity.MainActivity">

<!-- Appbar -->

<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<!-- Toolbar -->

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>


MainActivity.java



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);

mTitle = mToolbar.findViewById(R.id.toolbar_title);


These gives me that:



enter image description here



But I want it to be like standard behavior:
enter image description here



I tried a lot of solution, like transparency styles for bar etc. Bo I cannot figure it out.



Could you help me?










share|improve this question




















  • 1





    You need to use android.support.design.widget.CoordinatorLayout as your rootlayout stackoverflow.com/questions/52639958/…

    – Nilesh Rathod
    Nov 22 '18 at 10:15


















0















I've created custom toolbar layout because I wanted to have a centered title on bar. The code looks like this:



main_activity.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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainactivity.MainActivity">

<!-- Appbar -->

<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<!-- Toolbar -->

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>


MainActivity.java



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);

mTitle = mToolbar.findViewById(R.id.toolbar_title);


These gives me that:



enter image description here



But I want it to be like standard behavior:
enter image description here



I tried a lot of solution, like transparency styles for bar etc. Bo I cannot figure it out.



Could you help me?










share|improve this question




















  • 1





    You need to use android.support.design.widget.CoordinatorLayout as your rootlayout stackoverflow.com/questions/52639958/…

    – Nilesh Rathod
    Nov 22 '18 at 10:15
















0












0








0








I've created custom toolbar layout because I wanted to have a centered title on bar. The code looks like this:



main_activity.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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainactivity.MainActivity">

<!-- Appbar -->

<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<!-- Toolbar -->

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>


MainActivity.java



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);

mTitle = mToolbar.findViewById(R.id.toolbar_title);


These gives me that:



enter image description here



But I want it to be like standard behavior:
enter image description here



I tried a lot of solution, like transparency styles for bar etc. Bo I cannot figure it out.



Could you help me?










share|improve this question
















I've created custom toolbar layout because I wanted to have a centered title on bar. The code looks like this:



main_activity.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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainactivity.MainActivity">

<!-- Appbar -->

<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<!-- Toolbar -->

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>


MainActivity.java



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);

mTitle = mToolbar.findViewById(R.id.toolbar_title);


These gives me that:



enter image description here



But I want it to be like standard behavior:
enter image description here



I tried a lot of solution, like transparency styles for bar etc. Bo I cannot figure it out.



Could you help me?







android android-layout toolbar android-appbarlayout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 9:52









Rahul Chandrabhan

1,84341322




1,84341322










asked Nov 22 '18 at 9:08









northenofcanorthenofca

135




135








  • 1





    You need to use android.support.design.widget.CoordinatorLayout as your rootlayout stackoverflow.com/questions/52639958/…

    – Nilesh Rathod
    Nov 22 '18 at 10:15
















  • 1





    You need to use android.support.design.widget.CoordinatorLayout as your rootlayout stackoverflow.com/questions/52639958/…

    – Nilesh Rathod
    Nov 22 '18 at 10:15










1




1





You need to use android.support.design.widget.CoordinatorLayout as your rootlayout stackoverflow.com/questions/52639958/…

– Nilesh Rathod
Nov 22 '18 at 10:15







You need to use android.support.design.widget.CoordinatorLayout as your rootlayout stackoverflow.com/questions/52639958/…

– Nilesh Rathod
Nov 22 '18 at 10:15














1 Answer
1






active

oldest

votes


















1














Using ConstraintLayout is not a good idea in there since maybe you'll need to hide or give the layout some effects later.



Instead, use CoordinatorLayout as the root of the layout and remove ConstraintLayout with it's attributes:



<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Appbar -->

<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">

<!-- Toolbar -->

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>


AndroidX (Newer versions):



<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Appbar -->

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">

<!-- Toolbar -->

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>


Output:



enter image description here






share|improve this answer
























  • Thank you. Sorry for so late answer, but I has something come around and I hadn't time to answer you. If in my main ConstraintLayout I also have an include view and BottomNavigationView, should I still be using CoordinatorLayout? 'Code': <CoordinatorLayout > <AppBarLayout> <Toolbar> <TextView/> </Toolbar> <AppBarLayout> <include /> <BottomNavigationView /> </CoordinatorLayout>

    – northenofca
    Nov 26 '18 at 8:40













  • @Nilesh Rathod Could you look at that^ comment also?

    – northenofca
    Nov 26 '18 at 9:51











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',
autoActivateHeartbeat: false,
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%2f53427299%2fbackground-overlapsing-notification-bar-while-using-custom-toolbar-with-appbarla%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Using ConstraintLayout is not a good idea in there since maybe you'll need to hide or give the layout some effects later.



Instead, use CoordinatorLayout as the root of the layout and remove ConstraintLayout with it's attributes:



<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Appbar -->

<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">

<!-- Toolbar -->

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>


AndroidX (Newer versions):



<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Appbar -->

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">

<!-- Toolbar -->

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>


Output:



enter image description here






share|improve this answer
























  • Thank you. Sorry for so late answer, but I has something come around and I hadn't time to answer you. If in my main ConstraintLayout I also have an include view and BottomNavigationView, should I still be using CoordinatorLayout? 'Code': <CoordinatorLayout > <AppBarLayout> <Toolbar> <TextView/> </Toolbar> <AppBarLayout> <include /> <BottomNavigationView /> </CoordinatorLayout>

    – northenofca
    Nov 26 '18 at 8:40













  • @Nilesh Rathod Could you look at that^ comment also?

    – northenofca
    Nov 26 '18 at 9:51
















1














Using ConstraintLayout is not a good idea in there since maybe you'll need to hide or give the layout some effects later.



Instead, use CoordinatorLayout as the root of the layout and remove ConstraintLayout with it's attributes:



<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Appbar -->

<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">

<!-- Toolbar -->

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>


AndroidX (Newer versions):



<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Appbar -->

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">

<!-- Toolbar -->

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>


Output:



enter image description here






share|improve this answer
























  • Thank you. Sorry for so late answer, but I has something come around and I hadn't time to answer you. If in my main ConstraintLayout I also have an include view and BottomNavigationView, should I still be using CoordinatorLayout? 'Code': <CoordinatorLayout > <AppBarLayout> <Toolbar> <TextView/> </Toolbar> <AppBarLayout> <include /> <BottomNavigationView /> </CoordinatorLayout>

    – northenofca
    Nov 26 '18 at 8:40













  • @Nilesh Rathod Could you look at that^ comment also?

    – northenofca
    Nov 26 '18 at 9:51














1












1








1







Using ConstraintLayout is not a good idea in there since maybe you'll need to hide or give the layout some effects later.



Instead, use CoordinatorLayout as the root of the layout and remove ConstraintLayout with it's attributes:



<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Appbar -->

<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">

<!-- Toolbar -->

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>


AndroidX (Newer versions):



<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Appbar -->

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">

<!-- Toolbar -->

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>


Output:



enter image description here






share|improve this answer













Using ConstraintLayout is not a good idea in there since maybe you'll need to hide or give the layout some effects later.



Instead, use CoordinatorLayout as the root of the layout and remove ConstraintLayout with it's attributes:



<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Appbar -->

<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">

<!-- Toolbar -->

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>


AndroidX (Newer versions):



<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Appbar -->

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">

<!-- Toolbar -->

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>


Output:



enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 10:31









ʍѳђઽ૯ทʍѳђઽ૯ท

10.6k42877




10.6k42877













  • Thank you. Sorry for so late answer, but I has something come around and I hadn't time to answer you. If in my main ConstraintLayout I also have an include view and BottomNavigationView, should I still be using CoordinatorLayout? 'Code': <CoordinatorLayout > <AppBarLayout> <Toolbar> <TextView/> </Toolbar> <AppBarLayout> <include /> <BottomNavigationView /> </CoordinatorLayout>

    – northenofca
    Nov 26 '18 at 8:40













  • @Nilesh Rathod Could you look at that^ comment also?

    – northenofca
    Nov 26 '18 at 9:51



















  • Thank you. Sorry for so late answer, but I has something come around and I hadn't time to answer you. If in my main ConstraintLayout I also have an include view and BottomNavigationView, should I still be using CoordinatorLayout? 'Code': <CoordinatorLayout > <AppBarLayout> <Toolbar> <TextView/> </Toolbar> <AppBarLayout> <include /> <BottomNavigationView /> </CoordinatorLayout>

    – northenofca
    Nov 26 '18 at 8:40













  • @Nilesh Rathod Could you look at that^ comment also?

    – northenofca
    Nov 26 '18 at 9:51

















Thank you. Sorry for so late answer, but I has something come around and I hadn't time to answer you. If in my main ConstraintLayout I also have an include view and BottomNavigationView, should I still be using CoordinatorLayout? 'Code': <CoordinatorLayout > <AppBarLayout> <Toolbar> <TextView/> </Toolbar> <AppBarLayout> <include /> <BottomNavigationView /> </CoordinatorLayout>

– northenofca
Nov 26 '18 at 8:40







Thank you. Sorry for so late answer, but I has something come around and I hadn't time to answer you. If in my main ConstraintLayout I also have an include view and BottomNavigationView, should I still be using CoordinatorLayout? 'Code': <CoordinatorLayout > <AppBarLayout> <Toolbar> <TextView/> </Toolbar> <AppBarLayout> <include /> <BottomNavigationView /> </CoordinatorLayout>

– northenofca
Nov 26 '18 at 8:40















@Nilesh Rathod Could you look at that^ comment also?

– northenofca
Nov 26 '18 at 9:51





@Nilesh Rathod Could you look at that^ comment also?

– northenofca
Nov 26 '18 at 9:51




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427299%2fbackground-overlapsing-notification-bar-while-using-custom-toolbar-with-appbarla%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

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith