【问题标题】:How to delete this bar from Android app?如何从 Android 应用程序中删除此栏?
【发布时间】:2017-04-30 11:33:41
【问题描述】:

我从朋友那里得到了这个源代码,他在其中实现了抽屉式导航菜单,但我想删除它。我从 main.java 中删除了关于抽屉的所有内容,但我在我的应用程序中看到了这一点:

我指的是带有名称的白条。

这是一个布局代码:

<android.support.v4.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"
android:background="#fff >





<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout android:id="@+id/content_frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:layout_below="@+id/toolbar_app_bar_layout">




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

    </RelativeLayout>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/toolbar_app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:gravity="center"
            android:orientation="vertical" >

            <include
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                layout="@layout/top_points_bar" />
        </LinearLayout>
        <android.support.design.widget.TabLayout
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/toolbar"
            app:tabMode="scrollable"
            app:paddingStart="16dp"
            app:tabPaddingStart="16dp"
            app:tabPaddingEnd="16dp"
            app:tabMinWidth="96dp"
            app:tabGravity="center" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />


</RelativeLayout>

<android.support.design.widget.NavigationView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/navigation_view"

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="start"
    android:background="@color/md_brown_100"
    app:menu="@menu/menu_drawer"
    android:textColor="@color/okurwa"
    android:visibility="gone"
    app:theme="@style/MyTabStyle"
    app:headerLayout="@layout/nav_drawer_header"
    app:itemTextAppearance="@style/MyTabTextStyle"
    android:clipToPadding="false">
    <include
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/md_white_1000"
        android:visibility="gone"
        layout="@layout/nav_drawer_header"
        android:orientation="vertical"

        />





    <TextView
        android:id="@+id/nav_drawer_wallet_id"
        android:layout_width="177dp"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        android:layout_marginTop="8dp"
        android:layout_marginLeft="16dp"
        android:layout_marginBottom="8dp"/>

    <TextView
        android:id="@+id/nav_drawer_total_credits"
        android:layout_width="182dp"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:layout_marginTop="200dp"
        android:layout_marginLeft="16dp" />

    <TextView
        android:id="@+id/nav_drawer_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:textSize="22sp"
        android:layout_marginTop="150dp"/>



    <!--<FrameLayout-->
        <!--android:layout_width="match_parent"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:layout_gravity="bottom"-->
        <!--android:background="@color/md_white_1000"-->
        <!--android:elevation="4dp"-->
        <!--android:layout_marginBottom="-96dp">-->

        <!--<Button android:id="@+id/navigation_button_footer"-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="match_parent"-->
            <!--android:text=""-->
            <!--android:textSize="13sp"-->
            <!--android:textColor="@color/md_grey_800"-->
            <!--android:lines="3"-->
            <!--android:gravity="center"-->
            <!--style="@style/Widget.AppCompat.ActionButton"-->
            <!--android:paddingTop="20dp"-->
            <!--android:paddingLeft="20dp"-->
            <!--android:paddingRight="20dp"-->
            <!--android:paddingBottom="20dp"/>-->

    <!--</FrameLayout>-->

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

<RelativeLayout
    android:id="@+id/lay_connection"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="@dimen/actmain_margintop"
    android:background="#3c3c3c"
    android:visibility="gone" >

    <TextView
        android:id="@+id/text_error"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:text="@string/error_no_internet"
        android:textColor="@color/md_white_1000"
        android:textSize="@dimen/twentyfive" />


    <RelativeLayout
        android:id="@+id/lay_dialog"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone" >

        <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/progressBar1"
            android:layout_centerHorizontal="true"
            android:text="@string/error_no_internet"
            android:textColor="@color/md_white_1000"
            android:textSize="@dimen/twentyfive" />
    </RelativeLayout>
</RelativeLayout>

而且,当用户滑动它时它会删除一个左侧菜单吗? 请帮帮我!我想我尝试了所有解决方案。

【问题讨论】:

    标签: android android-layout android-toolbar


    【解决方案1】:

    您可以在 style.xml 文件中使用"@style/Theme.AppCompat.Light.NoActionBar",如下所述:remove-android-app-title-bar

    或者你可以添加

    getSupportActionBar().hide();

    在您的活动的onCreate() 中。

    【讨论】:

    • 它删除了此栏中的应用名称,但该栏已存在
    • 试试getSupportActionBar().hide()
    • setDisplayShowTitleEnabled ?真的吗? OP 想要删除 Toolbar 而不是隐藏标题!请注意...
    【解决方案2】:

    他在其中实现了抽屉式导航菜单,但我想删除 它。我从 main.java 中删除了关于抽屉的所有内容

    如果您尝试删除所有 NavigationDrawer 实现,则必须删除 xml 布局中的 DrawerLayout 和 NavigationDrawer 代码。

    这是有关此的文档:(首先了解它的工作原理并了解实现,然后将它们全部删除)

    https://developer.android.com/training/implementing-navigation/nav-drawer.html

    所以,您必须删除它,但您并没有真正提及某些事情,关于那个(白色部分)-(我们称之为Toolbar BTW)如果您正在尝试要删除它,因为我在您的 xml 中看不到 Toolbar 代码,那么您必须对布局进行重大更改。

    在上述删除之后,删除NavigationView,它是NavigationDrawer 实现的一部分。

    还有,当用户滑动左侧菜单时,它会删除它吗?

    当然,是的。毕竟,您需要删除此文件:

    @menu/menu_drawer
    

    无论如何,我没有说任何关于 TabLayout 的内容,我在您添加的图像上看不到具有此名称的东西,所以,我需要查看布局预览而不是此图像...

    但是,如果您想删除Toolbar,您可能需要更改或删除AppBarLayout。

    看看CoordinatorLayout 的这个实现。它将帮助您创建新布局:

    https://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      • 2020-03-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-02
      相关资源
      最近更新 更多