Android中的透明Actiobar

The*_*Man 3 android android-actionbar

我试图给我的行动栏透明效果.我使用了以下一行来使它以这种方式工作,但奇怪的是在我的Nexus 5上我可以看到酒吧即将到来,但在我的银河系nexus我根本看不到它.

我不知道为什么N5会出现这种情况?如何解决这个问题?

这是代码:

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setDisplayShowHomeEnabled(false);
    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    setContentView(R.layout.profile);
Run Code Online (Sandbox Code Playgroud)

以下是运行Jelly Bean(4.3)的Galaxy nexus和运行kitkat(4.4.4)的Nexus 5的屏幕截图

Galaxy Nexus:完美呈现透明动作条:

在此输入图像描述

Nexus 5:显示透明操作栏:(显示水平线)

在此输入图像描述

更新2:

我设法通过使用以下样式删除N5上的行

  styles.xml in Values-v14 folder

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

  then added theme to specific activity in manifext:

      <activity
        android:name=".Profile"
        android:label="@string/profile"
        android:theme="@style/CustomActionBarTheme"
        android:screenOrientation="portrait" >
Run Code Online (Sandbox Code Playgroud)

但是在此活动中我的所有文本,对话框格式都已更改.它变得黑暗.即使我以编程方式更改对话框的主题,它也不会更改.我不确定是什么问题?有人可以帮我解决这个问题吗?

更新1:根据@erakitn建议:我尝试了以下几个更改:

<!-- Transparent ActionBar Style -->
<style name="CustomThemeTransparent" parent="AppBaseTheme">
    <item name="android:background">@android:color/transparent</item>
    <item name="background">@android:color/transparent</item>
</style>

<!-- Activity Theme with transparent ActionBar -->
<style name="CustomThemeTransparentLight" parent="AppBaseTheme">
    <item name="android:actionBarStyle">@style/CustomThemeTransparent</item>
    <item name="actionBarStyle">@style/CustomThemeTransparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="windowActionBarOverlay">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

1. error: Error: No resource found that matches the given name: attr 'background'.
2. error: Error: No resource found that matches the given name: attr 'actionBarStyle'.
3. error: Error: No resource found that matches the given name: attr 'windowActionBarOverlay'.
Run Code Online (Sandbox Code Playgroud)

era*_*tin 10

要删除ActionBar阴影,请尝试向<item name="android:windowContentOverlay">@null</item>Activity主题添加属性.下面是一个透明ActionBar的主题示例.定义它res/styles.xml:

<!-- Your App Theme-->
<style name="YourAppTheme.Light" parent="@style/Theme.AppCompat.Light">
    <...>
</style>

<!-- Transparent ActionBar Style -->
<style name="YourAppTheme.Light.ActionBar.Transparent" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="android:background">@android:color/transparent</item>
    <item name="background">@android:color/transparent</item>
</style>

<!-- Activity Theme with transparent ActionBar -->
<style name="YourAppTheme.TransparentActionBar.Light" parent="@style/YourAppTheme.Light">
    <item name="android:actionBarStyle">@style/YourAppTheme.Light.ActionBar.Transparent</item>
    <item name="actionBarStyle">@style/YourAppTheme.Light.ActionBar.Transparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="windowActionBarOverlay">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

并将此主题设置为您的活动:

<activity
    android:name="your.package.name.YourActivity"
    android:label="@string/app_name"
    android:theme="@style/YourAppTheme.TransparentActionBar.Light" />
Run Code Online (Sandbox Code Playgroud)

UPD:

如果您不使用AppCompat或ABS,则应使用HOLO主题作为主题的父级.看起来你使用浅色主题和黑暗的ActionBar.请尝试以下解决方案:

<!-- Your App Theme-->
<style name="YourAppTheme.Light" parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <...>
</style>

<!-- Transparent ActionBar Style -->
<style name="YourAppTheme.Light.ActionBar.Transparent" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@android:color/transparent</item>
</style>

<!-- Activity Theme with transparent ActionBar -->
<style name="YourAppTheme.TransparentActionBar.Light" parent="@style/YourAppTheme.Light">
    <item name="android:actionBarStyle">@style/YourAppTheme.Light.ActionBar.Transparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:windowActionBarOverlay">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)