Removing line or divider between action bar and main screen in Android
Asked Answered
S

8

7

How can I remove line or divider between action bar and main screen? How can I change the color of this divider in android? Thanks in advance.

Sklar answered 22/3, 2014 at 21:51 Comment(2)
possible duplicate of I want to remove the divider under the action barGilgilba
I saw that question before but I can't remove divider with those answers, can you explain, divider related to which style of action bar.and I of course explain that I don.t need overlay Action bar. I just remove that line such as you have style Theme.Holo.Light.NoActionBar in your project.Sklar
S
6

After more effort I can find my ideal Theme.

  1. First of all i must say that Theme.Holo.Light has a shadow in bottom of action bar if you want to have not that shadow you must use Theme.Holo.
  2. After you change the style you must change other settings for yourself like the code.

    <resources>
        <style name="AppTheme" parent="android:Theme.Holo">
            <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
            <item name="android:background">#ff0000</item>
            <item name="android:colorBackground">#ff0000</item>
        </style>
        <style name="AppTheme.ActionBar" parent="android:Widget.ActionBar">
            <item name="android:background">#ff0000</item>
        </style>
    </resources>
    
  3. This below code is for my last challange that I found how to resolve it.

    <resources>
        <style name="AppTheme" parent="android:Theme.Holo.Light">
            <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
            <item name="android:background">#ff0000</item>
            <item name="android:colorBackground">#ff0000</item>
        </style>
        <style name="AppTheme.ActionBar" parent="android:Widget.ActionBar">
            <item name="android:background">#ff0000</item>
        </style>
    </resources>
    
  4. Below Image is for first Code, If you notice there isn't any divider.

enter image description here

  1. And below Image is for second Code.

enter image description here

Sklar answered 23/3, 2014 at 10:44 Comment(1)
Thanks for android:Theme.Holo :)Thersathersites
A
13

Simply insert the attribute windowContentOverlay to your theme. It's way too simple this way.

<style name="AppTheme" parent="android:Theme.Holo.Light">
    <!-- Customize your theme here. -->
    <item name="android:windowContentOverlay">@null</item>
</style>
Arne answered 30/9, 2014 at 7:8 Comment(1)
This removes only the shadow, not the lineBurnt
S
6

After more effort I can find my ideal Theme.

  1. First of all i must say that Theme.Holo.Light has a shadow in bottom of action bar if you want to have not that shadow you must use Theme.Holo.
  2. After you change the style you must change other settings for yourself like the code.

    <resources>
        <style name="AppTheme" parent="android:Theme.Holo">
            <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
            <item name="android:background">#ff0000</item>
            <item name="android:colorBackground">#ff0000</item>
        </style>
        <style name="AppTheme.ActionBar" parent="android:Widget.ActionBar">
            <item name="android:background">#ff0000</item>
        </style>
    </resources>
    
  3. This below code is for my last challange that I found how to resolve it.

    <resources>
        <style name="AppTheme" parent="android:Theme.Holo.Light">
            <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
            <item name="android:background">#ff0000</item>
            <item name="android:colorBackground">#ff0000</item>
        </style>
        <style name="AppTheme.ActionBar" parent="android:Widget.ActionBar">
            <item name="android:background">#ff0000</item>
        </style>
    </resources>
    
  4. Below Image is for first Code, If you notice there isn't any divider.

enter image description here

  1. And below Image is for second Code.

enter image description here

Sklar answered 23/3, 2014 at 10:44 Comment(1)
Thanks for android:Theme.Holo :)Thersathersites
B
5

None of these solutions worked for me. I ended up adding this code to the onCreate() event of my MainActivity:

actionBar = getSupportActionBar();
actionBar.setElevation(0);
Bova answered 23/5, 2019 at 23:41 Comment(0)
E
3

On Kotlin, you can use supportActionBar?.elevation = 0f to remove the shadow of the ActionBar.

Add this code to the onCreate() function of the desired activity. For example:

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

        // Hide ActionBar shadow
        supportActionBar?.elevation = 0f
    }

The ?. operator controls Null Pointer Exception if you have no ActionBar on this Activity.

Note: If you are not using AppCompat, call actionBar?.elevation = 0f instead.

Este answered 31/10, 2019 at 14:1 Comment(0)
B
2

This worked for me:

I just added the following line of code to the onCreate() method

 getSupportActionBar().setElevation(0);
Bendwise answered 14/7, 2020 at 16:7 Comment(0)
S
1

If you use AppCompat you need set parent="Theme.AppCompat", not "Theme.AppCompat.Light" (the same stands for ActionBar) :)

For example: @style/MyActionBar true @style/MyActionBar true

<style name="MyActionBar" parent="Base.Widget.AppCompat.ActionBar">
    <item name="android:background">@android:color/transparent</item>
    <!--For compatibility-->
    <item name="background">@android:color/transparent</item>
</style>
Shingles answered 22/5, 2015 at 11:48 Comment(0)
H
0

In your styles.xml file , look for your AppTheme style and add the following style into it

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

like this

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:fontFamily">@font/roboto</item>
    <item name="android:actionBarDivider">@android:color/transparent</item>
</style>

what it actually does is that it sets the background of the divider between activity window and action bar as transparent.

Horbal answered 6/5, 2018 at 14:0 Comment(0)
S
0

In case you are using AppBarLayout nothing of that will help. I found the solution using :

        AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout);
        appBarLayout.setOutlineProvider(null);
Searching answered 28/1, 2020 at 9:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.