【问题标题】:Two Toolbars Showing两个工具栏显示
【发布时间】:2018-04-02 09:47:03
【问题描述】:

我最近在我的应用程序中添加了一个 CoordinatorLayout。如何删除显示在其他工具栏下方的蓝色框。我已经尝试删除 appbar 布局和导航视图,但它们没有导致任何更改。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context="com.example.recyclerviewtutorial.ChatListActivity">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/layout_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_chats"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            app:srcCompat="@drawable/ic_info_black_24dp"/>

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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
       />


</LinearLayout>

编辑 Styles.xml 被添加。

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

只是一些随机的文字来满足发帖要求 编辑 问题已解决

我在 AppBarLayout 中添加了一个 ID

android:id="@+id/appbar_nav"

并在 Activity 的 onCreate 方法中禁用它。

AppBarLayout mAppBarLayout = findViewById(R.id.appbar_nav);
mAppBarLayout.setVisibility(View.GONE);

【问题讨论】:

  • 显示你的styles.xml
  • 设置apptheme noactionbar
  • 使用NoActionBar主题。
  • 如果你想要自定义工具栏,你必须使用noactionbar

标签: java android xml android-layout


【解决方案1】:

将此主题设置为您的 styles.xml 文件。

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

【讨论】:

    【解决方案2】:

    您可以在 style.xml 中执行此操作

    <style name="AppTheme.NoActionBar">
       <!-- <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>-->
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>
    

    并将这种样式赋予清单中的活动,例如,

     <activity
            android:name=".MainActivity"
            android:theme="@style/AppTheme.NoActionBar"
            android:label="@string/app_name">
    
        </activity>
    

    额外:

    如果你想要透明的状态栏而不是添加 java 代码,

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow(); // in Activity's onCreate() for instance
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }
        setContentView(R.layout.activity_login);
    }
    

    【讨论】:

      【解决方案3】:

      您应该将以下主题设置为您的应用程序主题或活动主题

       <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
              <item name="colorPrimary">@color/colorPrimary</item>
              <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
              <item name="colorAccent">@color/colorAccent</item>
              <item name="windowActionBar">false</item>
              <item name="windowNoTitle">true</item>
          </style>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-11
        • 1970-01-01
        • 1970-01-01
        • 2019-08-05
        相关资源
        最近更新 更多