如何从 ActionBar 中删除顶部边框阴影

2024-04-27

我正在开发一个新的 Android 应用程序,由于某种原因,这个新应用程序(我自己没有添加额外的代码)在操作栏上有一个顶部边框阴影。

好像是我使用 Android Studio 创建新项目时默认添加的。

我怎样才能有一个只有底部阴影的普通操作栏?

我尝试寻找解决方案,但是,所有结果都让人询问如何去除底部阴影。通常使用非常具体的代码片段来消除其中的所有阴影,这是我不想要的。


Edit:

main_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/main_drawer" />

</android.support.v4.widget.DrawerLayout>

内容_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.wer.wer.Main"
    tools:showIn="@layout/app_bar_main">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
</RelativeLayout>

nav_header_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/nav_header_height"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:src="@android:drawable/sym_def_app_icon" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="Android Studio"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="[email protected] /cdn-cgi/l/email-protection" />

</LinearLayout>

app_bar_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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.wer.wer.Main">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.AppBarOverlay" />

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

    <include layout="@layout/content_main" />

    <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"
        android:src="@android:drawable/ic_menu_edit" />

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

清单.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wer.wer">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Main"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

首先,转到“activity_main.xml”并更改

android:fitsSystemWindows="true"

to

android:fitsSystemWindows="false"

或者直接删除该行。

然后阴影就会消失,但是状态栏的颜色会错误。

转到“styles-v21.xml”并删除该行

<item name="android:statusBarColor">@android:color/transparent</item>

或将颜色更改为您想要的任何颜色。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从 ActionBar 中删除顶部边框阴影 的相关文章

随机推荐

  • 关于 GK 成就的完成百分比

    经过测试 我发现GKAchievement的percentComplete类型虽然是double 但在苹果的帮助文档中合法值是在0 0到100 0之间 但是如果你向苹果服务器报告percentComplete 1 5 下次你将得到值perc
  • Visual Studio 编辑器边距中的蓝线

    使用 Visual Studio 时 我在页边空白处看到这些蓝线 我知道黄线和绿线表示编辑 但在蓝线上找不到任何内容 有谁知道他们的意思吗 Visual Studio 使用三种颜色来跟踪变化 yellow 保存前进行更改 green 保存后
  • Windows 7 SDK安装失败

    我好像完全无法安装Windows 7 SDK http en wikipedia org wiki Microsoft Windows SDK到我的机器上 我在网上找到的唯一解决方案是进行一系列注册表更改 我已经这样做了 仍然没有成功 这是
  • 部分类继承

    我正在为 Windows Phone 制作一个单位转换器 但我在类继承方面遇到了一些问题 我有课Measurement这应该是我的程序中图形内容的顶级 public class Measurement PhoneApplicationPag
  • matplotlib:Humor Sans 无法正确显示重音

    如果我选择 Humor Sans 这就是我从 matplotlib 得到的结果 因此 DIST NCIA 显示为 DIST NCIA 与其他字体一起显示效果很好 代码在这里 coding utf 8 from matplotlib impo
  • 序列化 - 如何保护序列化的 JAVA 对象?

    如果通过网络发送序列化对象 如何保护序列化对象的安全 我怀疑黑客可能会中断 破解我的数据 谁能详细讲述如何实现这一点 本演示介绍了攻击者如何有效地篡改 Java 序列化流 https www owasp org images e eb OW
  • Numpy 逐元素点积

    有没有一种优雅的 numpy 的方法来按元素应用点积 或者如何将下面的代码翻译成更好的版本 m0 shape 5 3 2 2 m1 shape 5 2 2 r np empty 5 3 2 2 for i in range 5 for j
  • 检查注释是否属于特定类型

    我正在使用反射来查看附加到类属性的注释是否属于特定类型 目前我正在做的 if javax validation Valid equals annotation annotationType getName 这让我觉得有点麻烦 因为它依赖于一
  • 为什么通过UdpClient发送会导致后续接收失败?

    我正在尝试创建一个 UDP 服务器 它可以向所有向其发送消息的客户端发送消息 真实情况要复杂一些 但最简单的方法是将其想象为一个聊天服务器 之前发送过消息的每个人都会收到其他客户端发送的所有消息 所有这一切都是通过UdpClient 在单独
  • LongListSelector 内的缓慢故事板动画

    我有一个 LongListSelector 其中填充了一些项目 每个项目都有一个子菜单 可以使用滑动动画显示或折叠该子菜单 问题是动画非常慢 具体取决于您在列表中点击的项目 开始和结束的时候很慢 中间很顺利 我怀疑每个动画帧都会使长列表选择
  • 将行添加到文件开头

    我可以使用单独的文件来执行此操作 但如何在文件的开头附加一行 f open log txt a f seek 0 get to the first position f write text f close 由于文件是以附加模式打开的 因此
  • cmake 在执行其他操作之前执行进程

    我在执行其他操作之前 CMake 执行进程时遇到问题 下面的代码片段显示了这种情况 if NOT EXISTS CMAKE CURRENT BINARY DIR generated file MAKE DIRECTORY CMAKE CUR
  • a 是什么意思? (点)在 PHP 中做什么?

    以下命令在 PHP 中执行什么操作 string string is something which I declared in the program 就其本身而言 它根本没有任何作用 它不是有效的语法 但是 如果你有这样的事情 你会看见
  • 如何通过命令行缩小/扩大 aws ecs 集群中的容器,我应该使用 aws cli 还是 ecs-cli?

    我正在使用 EC2 实例运行 AWS ECS 集群 我想要一个命令将任务扩展到 1 个正在运行的实例 然后在一段时间后 当我不需要它时 我想将其缩小到 0 这应该会破坏底层 EC2实例以避免收费 我没有使用 Fargate 因为它不属于免费
  • XML布局在android studio中不换行

    在我更新 android studio 后 布局编辑器中的 XML 格式被破坏了 最初 每个属性都位于单独的行上 然而现在有两个或三个属性占据一条线 我进入 设置 gt 编辑器 gt 代码样式 gt XML 在 布局文件 区域下 将 换行属
  • 旋转 UISplitViewController 后模态消失

    我有一个奇怪的问题 UISplitViewController 我的主视图控制器中有一个按钮 点击时会打开一个模式视图 使用简单的故事板转场 但是 当我旋转 iPad 时 模式视图会消失 但仅限于从纵向旋转到横向时 我的主视图控制器以纵向隐
  • Intellij Idea 中 Dockerfile 部署失败(未连接到 docker)

    我是 Docker 新手 只是想按照此中的说明进行操作 我创建了非常简单的 Dockerfile 但部署失败 问题是没有太多信息 Docker 已启动并正在运行 我可以从 IDE 连接到它 码头工人信息 如果您最近更改了 Docker De
  • DbContext.Entry 附加实体

    从我的研究中 我了解到调用 DbContext Entry someEntity 会自动将实体附加到上下文 然而 当我这样做时 我发现实体的状态是分离的 任何人都可以阐明这一点以及 DbContext Entry 的工作原理吗 我正在使用
  • 如何纠正 Rails 控制台命令的错误?

    当我位于 Rails 应用程序的根目录中时 我可以成功执行rails server 但是当我尝试做时rails console or rails c我收到以下错误 myrailsapp master rails c Users myuser
  • 如何从 ActionBar 中删除顶部边框阴影

    我正在开发一个新的 Android 应用程序 由于某种原因 这个新应用程序 我自己没有添加额外的代码 在操作栏上有一个顶部边框阴影 好像是我使用 Android Studio 创建新项目时默认添加的 我怎样才能有一个只有底部阴影的普通操作栏