Not show androidx.appcompat.widget.Toolbar

Android Studio 3.4

styles.xml

<style name="Main.Theme.Tango" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <!--   darker variant for the status bar and contextual app bars -->
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <!--   theme UI controls like buttons, checkboxes and text fields or cursor -->
        <item name="colorAccent">@color/colorAccent</item>
    </style>

in manifest:

<application
            android:name=".main.MainApp"
            android:allowBackup="true"
            android:icon="@drawable/ic_app"
            android:label="@string/application_name"
            android:logo="@drawable/ic_app_logo"
            android:theme="@style/Main.Theme.Tango" >

In activity:

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.widget.Toolbar;

public class MainNavigationDrawerFragmentActivity extends AppCompatActivity{

 private void initialize(Bundle savedInstanceState) {
        mTitle = mDrawerTitle = getTitle();

        mToolbar = (Toolbar) findViewById(R.id.toolBar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(false);



mDrawerToggle = new ActionBarDrawerToggle(
                this,
                mDrawerLayout,
                mToolbar, R.string.application_name,
                R.string.application_name) {
            public void onDrawerClosed(View view) {
                mToolbar.setTitle(mTitle);
                invalidateOptionsMenu();
            }

    public void onDrawerOpened(View drawerView) {

        mToolbar.setTitle(mDrawerTitle);
        invalidateOptionsMenu();
        loadDraftsTotalNumber();
        loadActiveCart();
    }
};
    mDrawerLayout.setDrawerListener(mDrawerToggle);

and here layout:

<androidx.drawerlayout.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

  <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolBar"
        android:layout_width="0dp"
        android:layout_height="56dp"
        android:background="#dc2700"

    <FrameLayout
            android:id="@+id/frame_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    </FrameLayout>


    <!-- Listview to display slider menu -->

    <ListView
            android:id="@+id/list_slidermenu"
            android:layout_width="288dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@color/list_background"
            android:choiceMode="singleChoice"
            android:divider="@null"
            android:listSelector="@drawable/list_selector"
            android:paddingLeft="16dip"
            android:paddingRight="16dip"/>

</androidx.drawerlayout.widget.DrawerLayout>

but toolbar not show:

Try this for your layout. It works for me.

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/color3"
    app:layout_constraintTop_toTopOf="parent">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolBar"
        android:layout_width="0dp"
        android:layout_height="56dp"
        android:background="#dc2700"
     />
</com.google.android.material.appbar.AppBarLayout>

Using the App Toolbar, In AppCompat, Toolbar is implemented in the androidx.appcompat.widget. Action Bar would not support; for example, showing multiple toolbars on the screen,� why not show androidx.appcompat.widget.Toolbar. Ask Question Asked 9 days ago. Active 9 days ago. Viewed 21 times -1. I create a BaseActivity to create a toolbar and

Try setting android:layout_width="match_parent" for toolBar

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

Not working with androidx.appcompat.widget.Toolbar � Issue #1 , I tried to use this library as such: <androidx.appcompat.widget.Toolbar android:id ="@+id/toolbar" android:layout_alignParentTop="true"� import androidx.appcompat.widget.Toolbar; By the way, if you are using androidx. Run it's migration process. The android support libraries will not be supported in the future. You can read about it here: AndroidX Migrating to AndroidX

I found solution

The toolbar AND FrameLayout must be inside LinearLayout:

   <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

         <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolBar"
            android:layout_width="match_parent"
            android:layout_height="56dp"/>


        <!-- Framelayout to display Fragments -->
        <FrameLayout
                android:id="@+id/frame_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
        </FrameLayout>
    </LinearLayout>

and here result:

Toolbar, public class Toolbar android.view.ViewGroup. ↳, androidx.appcompat.widget. Toolbar Hide the overflow items from the associated menu. if your project is already migrated to AndroidX then import this import androidx.appcompat.widget.Toolbar; else migrate to AndroidX by Refactor>Migrate to AndroidX Full code Example of XML and Java

Set up the app bar, For example, the Toolbar widget provides a material design experience action bar doesn't support material design unless the device is running Android Add the v7 appcompat support library to your project, as described in Support Library Setup. For example, to hide the app bar, call ActionBar.hide() . A standard toolbar for use within application content. A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy.

Class androidx.appcompat.widget.Toolbar, Check whether this Toolbar is currently hosting an expanded action view. public boolean, hideOverflowMenu(). Hide the overflow items from the associated menu . Wherever you want to use it in XML or in java instead of android.support.v7.widget.Toolbar use androidx.appcompat.widget.Toolbar and it should work show 2 more

Using the Android Toolbar (ActionBar) - Tutorial, This tutorial describes how to use the toolbar widget in your Android application. dependency to com.android.support:appcompat to your Gradle build file. SYSTEM_UI_FLAG_FULLSCREEN // hide status bar // remove the� On a device running Lollipop shows the shadow because of the elevation attribute but not on KitKat or older versions. Thats the expected behavior for the elevation attribute as documentation says, but I was expecting that, by default without the elevation attribute, the shadow would cast like it does the Action Bar on every version.

Comments
  • Dont you need to have an action bar around toolbar?
  • @ChrisPapantonis No, I need only toolbar in ActionBarDrawerToggle
  • I found solution. See my answer