ActionBarCompat和放大器;透明度放大器、透明度、ActionBarCompat

2023-09-05 06:34:34 作者:专情目光

我想作的动作条中的支持库完全透明的,但是,似乎改变背景绘制是不够的,因为背景的叠加。如果你把一个半透明的背景,你最终与它背后的默认背景。

I would like to make the ActionBar in the support library fully transparent, however, it seems that changing the background drawable won't suffice since the backgrounds stack. If you put a semi-transparent background you end up with the default background behind it.

有谁知道一个方法来消除这种背景下?

Does anyone know a way to remove that background?

这是发生了什么:

在code为背景绘制:

The code for the background drawable:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#66336688"/>
</shape>

正如你所看到的,可绘制有一个透明的蓝色,与默认的灰色背景重叠。

As you can see, the drawable has a transparent blue that overlaps with the default gray background.

推荐答案

好吧,我找到了解决方案与SDK瞎搞。 这似乎是pretty的简单,你需要做3件事情:

Ok, I found the solution messing around with the SDK. It seems that it is pretty simple, you need to do 3 things:

创建一个背景绘制如图所示对我的问题。

创建一个动作条的风格,像这样: Create a background drawable as shown on my question.

Create an ActionBar style like so:

<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ACTION BAR STYLES -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:background">@drawable/actionbar_background</item>
    <item name="android:windowActionBarOverlay">true</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/actionbar_background</item>
    <item name="windowActionBarOverlay">true</item>
</style>

使用支持方法使用的动作条重叠窗口功能(忽略Eclipse的关于为恒API级别警告;我用燮pressLint注释删除警告):

Use the Window feature for ActionBar overlay using the Support method (ignore Eclipse's warning regarding API level for the constant; I used the SuppressLint annotation to remove the warning):

@SuppressLint("InlinedApi") @Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
setContentView(R.layout.activity_home);}