首页 > 解决方案 > 删除操作栏下方的颜色

问题描述

所以我有 2 个标签,分别是 request 和 order in MainActivity

class MainActivity : BaseActivity() {

    private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
        when (item.itemId) {
            R.id.navigation_request -> {
                changeFragment(
                    R.string.work_request,
                    WorkRequestFragment()
                )
                fab.setOnClickListener { _ ->
                    startActivity(Intent(this, CreateWorkRequestActivity::class.java))
                }
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_order -> {
                changeFragment(R.string.title_fragment_work_order,
                    WorkOrderFragment()
                )
                fab.setOnClickListener { _ ->
                    fab.setOnClickListener { _ ->
                        startActivity(Intent(this@MainActivity, CreateWorkOrderActivity::class.java))
                    }
                }
                return@OnNavigationItemSelectedListener true
            }
        }
        false
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
    }


    private fun changeFragment(title: Int, fragment: Fragment) {
        setTitle(title)
        supportFragmentManager.beginTransaction()
            .replace(
                R.id.frame_container,
                fragment,
                getString(title))
            .addToBackStack(null).commit()
    }    
}

活动主

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".activity.activity.MainActivity">

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


    <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="0dp"
            android:layout_marginStart="0dp"
            android:background="?android:attr/windowBackground"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:menu="@menu/navigation"/>

</android.support.constraint.ConstraintLayout>

app_bar_main

<?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.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

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

    </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_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_gravity="bottom|end"
            android:layout_marginBottom="70dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            app:srcCompat="@drawable/ic_add"
            android:tint="@color/colorPrimary"/>

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

content_main

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
                                             android:layout_height="match_parent"
                                             app:layout_behavior="@string/appbar_scrolling_view_behavior"
                                             tools:context=".activity.activity.MainActivity">

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

</android.support.constraint.ConstraintLayout>

如何删除操作栏下方的蓝色?

https://i.stack.imgur.com/f4wWo.png

[1]:

标签: androidandroid-actionbarandroid-appbarlayout

解决方案


操作栏下方的东西称为阴影或高度。你有很多方法可以实现你想要的。

您可以使用两个工具栏而不是操作栏+工具栏并修改它们的属性。

但如果你想继续你的方法,你可以查看下面的链接:如何删除 android actionbar Shadow


推荐阅读