Overlaying the Action Bar not working

自闭症网瘾萝莉.ら 提交于 2019-12-23 06:56:35

问题


I was following official developer's guide to overlay actionbar.

my style.xml is as following:

<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

<style name="AppTheme" parent="AppBaseTheme">
    <item name="actionBarStyle">@style/CustomActionBarTheme</item>

</style>

<style name="CustomActionBarTheme"
    parent="@android:style/Theme.Holo">
    <item name="android:windowActionBarOverlay">true</item>
</style>

My midSdkVersion is 14 and expected output is similar to that on official guide:

.

instead, in my case the output is:

(I have set background color to activity...but it isn't overlaying action bar.)

Please help me if anything I'm doing is wrong.

EDIT:

I wanted similar action bar like this in airnb and many other apps. Can anyone give me complete answer for this?


回答1:


I see some misunderstandings in your code:

  1. windowActionBarOverlay should be specified on your theme not on your ActionBar's style.
  2. No reason to use a Holo with a support theme. This just breaks your supportability.

Try this:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:windowActionBarOverlay">true</item>
    <!--For compatibility-->
    <item name="actionBarStyle">@style/MyActionBar</item>
    <item name="windowActionBarOverlay">true</item>
</style>

<color name="transparent_black">#80000000</color>
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar.Solid">
    <item name="android:background">@color/transparent_black</item>
    <!--For compatibility-->
    <item name="background">@color/transparent_black</item>
</style>



回答2:


i think you miss this point of developer guide

Enable Overlay Mode

For Android 3.0 and higher only

style.xml

<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo">
        <item name="android:windowActionBarOverlay">true</item>
    </style>
</resources>

For Android 2.1 and higher

<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.AppCompat">
        <item name="android:windowActionBarOverlay">true</item>

        <!-- Support library compatibility -->
        <item name="windowActionBarOverlay">true</item>
    </style>
</resources>

Specify Layout Top-margin

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?android:attr/actionBarSize">
    ...
</RelativeLayout>

and I have two example links Please have a Look on them for more clarification.

Android Tutorial: Overlay with User Instructions

Pushing the ActionBar to the Next Level




回答3:


Try this instead:

<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light.DarkActionBar">
</style>

<style name="OverlayActionBarTheme" parent="AppBaseTheme">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/Holo.ActionBar.Overlay</item>
</style>

<style
    name="Holo.ActionBar.Overlay"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">#80000000</item>
</style>



回答4:


After searching for two hours I feel obliedged to add this answer here.

What did the trick for me was to add all 6 of the following lines to styles.xml:

    <item name="android:windowActionModeOverlay">true</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowActionBar">true</item>

    <item name="windowActionModeOverlay">true</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="windowActionBar">true</item>

As far as I understand all those lines do the same thing, but different API levels only listen for certain lines. I should mention that I use minimum API level 19.




回答5:


You just missed that you need to set up the overlaying in your application theme as said in the documention

 <!-- the theme applied to the application or activity -->

Please feed back if the problem isn't solve with that ;)




回答6:


I do completely custom views, so, the activity layout would fill all the screen and put custom LinearLayout at the top with all the buttons and icons inflated



来源:https://stackoverflow.com/questions/28007921/overlaying-the-action-bar-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!