You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Kotlin音乐应用自定义ActionBar的边框

已解决!

我通过以下方法解决:
在themes.xml中添加配置:

<item name="elevation">0dp</item>

我正在用Kotlin开发一款音乐应用,给自定义ActionBar在主题中设置透明背景后,ActionBar莫名出现了边框,请问该怎么移除?

相关代码

action_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/actionBar"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <ImageButton
                        android:id="@+id/buttonBack"
                        android:layout_width="wrap_content"
                        android:layout_height="0dp"
                        android:background="@android:color/transparent"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintHorizontal_bias="0.0"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent"
                        app:srcCompat="@drawable/ic_back" />

                    <TextView
                        android:id="@+id/appTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="0dp"
                        android:layout_marginLeft="32dp"
                        android:gravity="center"
                        android:text="@string/app_name"
                        android:textColor="@color/white"
                        android:textSize="27sp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintStart_toEndOf="@+id/buttonBack"
                        app:layout_constraintTop_toTopOf="parent" />

                    <ImageButton
                        android:id="@+id/songListButton"
                        android:layout_width="wrap_content"
                        android:layout_height="0dp"
                        android:layout_marginEnd="16dp"
                        android:background="@android:color/transparent"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toTopOf="parent"
                        app:srcCompat="@drawable/ic_music" />
                </androidx.constraintlayout.widget.ConstraintLayout>

            </androidx.appcompat.widget.Toolbar>

        </androidx.constraintlayout.widget.ConstraintLayout>

    </com.google.android.material.appbar.AppBarLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

themes.xml

<resources xmlns:tools="http://schemas.android.com/tools">
    <style name="Base.Theme.MusicApplication" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowFullscreen">true</item>
        <item name="colorPrimaryDark">@color/black</item>
        <item name="colorPrimary">@android:color/transparent</item>
        <item name="android:editTextColor">@color/white</item>
    </style>

    <style name="Theme.MusicApplication" parent="Base.Theme.MusicApplication" />
</resources>

我完全不清楚出现这个边框的原因——检查过所有代码,从来没有给ActionBar设置过边框相关的属性。


内容的提问来源于stack exchange,提问作者heyz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 10:52:32