简体   繁体   中英

Transparent of Android Contextual Action Bar

A contexual action bar(CAB) will be shown when long tapping at TextEdit on Andriod WebView.

I specified the following styles, in order to avoid that a layout breaks, but menu doesn't became transparent and hide TextEdit. What should I write with this menu for making it transparent?

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="android:Theme.Holo">
        <item name="android:actionBarStyle">@style/AppStyle</item>
        <item name="android:windowActionModeOverlay">true</item>
    </style>
    <style name="AppStyle" parent="android:Widget.Holo.ActionBar">
        <item name="android:colorBackground">#00000000</item>
    </style>
</resources>

隐藏文字

Create a resource for your colors and reference them from there:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <color name="transparentBlack">#00000000</color>

</resources>

Change the AppStyle to this:

<style name="AppStyle" parent="android:Widget.Holo.ActionBar">

    <item name="android:background">@color/transparentBlack</item>

</style>

The main difference is background vs colorBackground, I'm not really sure if there is a functioning difference, but I know that when I compare my working transparent action bar style and your action bar style that is pretty much the only difference.

You could try to change only the android:colorBackground to android:background and see if that alone works, but I've found it best to use references instead of hard coding colors directly. If you are curious to change only one, try them separately to see if they solve your problem.

NEW SUGGESTION AS OF 12.22.2014-

Why don't you just hide the action bar (mSpecialActionBar.hide();) and then implement a View.OnLongClickListener for your Activity. You can then show the action bar again (mSpecialActionBar.show();) on a long click. Or something similar.

@Override
public void onLongClick(View v) {

    if (v.getClass() == TextEdit) {

       mSpecialActionBar.show();

    }
} // end-of-method onLongClick  

Here is a resource I found useful: http://java.dzone.com/articles/contextual-action-bar-cab

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM