Tony
Tony

Reputation: 2748

Remove the color below action bar

So I have 2 tabs, which are request and 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()
    }    
}

activity_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: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>

How can I remove the blue color below the action bar ?

https://i.sstatic.net/f4wWo.png

[1]:

Upvotes: 0

Views: 62

Answers (2)

Amir Hedieh
Amir Hedieh

Reputation: 1178

the thing under your action bar is called shadow or elevation. you have plenty ways to achieve what you want.

you can use two toolbars instead of action bar + toolbar and modify their attributes.

but if you want to continue your approach you can check link below: How can I remove android actionbar Shadow

Upvotes: 1

Ben P.
Ben P.

Reputation: 54224

Check the AndroidManifest.xml entry for your activity and see what's listed for the android:theme attribute. If the activity doesn't have this attribute, see what's listed for it under the <application> tag instead.

I assume that you're using a theme that provides an Action Bar, and then you're also including a Toolbar via app_bar_main.xml. You will have to decide which of these two you want.

If you want to use the theme-provided action bar, then you can just delete the <AppBarLayout> and <Toolbar> tags from app_bar_main.xml.

If you want to use the Toolbar specified in your layout, then you should use a NoActionBar theme for your activity. Generally, you'll see something like this:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

Change that to this instead:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

Upvotes: 0

Related Questions