java - 如何在 mainActivity 布局的工具栏中删除这个箭头?

标签 java android xml android-layout fragment

几周前,我添加了这个工具栏。我需要它用于滑动选项卡布局。 但是如果我安装apk,左上角会有一个后退箭头。

* Click *  Here you can see the arrow which should be removed

我不知道如何删除它。你能帮帮我吗?

如果您需要任何其他布局或类,请询问我。我将编辑问题。

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"  />
</android.support.design.widget.CoordinatorLayout>

这里是

styles.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

<style name="MyTheme" parent="MyTheme.Base">

</style>

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

</resources>

最佳答案

鉴于箭头的存在,我假设您将 Toolbar 设置为 ActionBar

如果是这样,修复就很简单了。只需调用

getActionBar().setDisplayHomeAsUpEnabled(false);

在调用 setActionBar(yourToolbar) 以确保没有空指针问题之后

关于java - 如何在 mainActivity 布局的工具栏中删除这个箭头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47475462/

相关文章:

java - 当远程计算机中未安装 cygwin 时,使用 Java 连接到远程 Windows 计算机

java - 无法可视化在链表末尾插入节点

android textpaint 看起来不像具有相同参数的 textview

Php 按日期排序多个 xmlDoc

xml - 如何使菜单项在odoo 10中不可见

java - 简化 XML 比较任务

java - 找不到 org.apache.thrift7.TBase 类

java - 标签根据用途不同大小

java - Android java Binder 失败的 Binder 交易

android - genymotion 蓝屏死机 windows 10