不显示androidx.appcompat.widget.Toolbar
Android Studio 3.4 styles.xml不显示androidx.appcompat.widget.Toolbar,android,android-toolbar,androidx,Android,Android Toolbar,Androidx,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>
<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>
这里是布局图:
<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>
为您的布局尝试此选项。它对我有用
<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>
为您的布局尝试此方法。它对我有用
<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>
我找到了解决方案
工具栏和框架布局必须位于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>
我找到了解决办法
工具栏和框架布局必须位于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>
尝试为工具栏设置android:layout\u width=“match\u parent”
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
尝试为工具栏设置android:layout\u width=“match\u parent”
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
您不需要在工具栏周围有一个操作栏吗?@ChrisPapantonis不,我只需要ActionBarDrawerToggle中的工具栏您不需要在工具栏周围有一个操作栏吗?@ChrisPapantonis不,我只需要ActionBarDrawerToggle中的工具栏我找到了解决方案。见我的答案,我找到了解决办法。看到我的答案了吗