GithubHelp home page GithubHelp logo

android-actionbar's Introduction

Action Bar for Android

Note This library is deprecated, use either v7 appcompat library or ActionBarSherlock.


ActionBar for Android

This projects aims to provide a reusable action bar component. The action bar pattern is well documented at Android Patterns.

The action bar component is an Library Project. This means that there's no need to copy-paste resources into your own project, simply add the action bar component as a reference to any project.

Need icons to your action bar? Olof Brickarp has ported some of Androids native icons to vector format.

Usage

In your layout

<com.markupartist.android.widget.ActionBar
    android:id="@+id/actionbar"
    app:title="@string/some_title"
    style="@style/ActionBar"
    />

The use of app:title is optional, it's also possible to assign the title using the setTitle programmatically on the ActionBar. To be able to use the more convenient app:title the application namespace must be included in the same manner as the android namespace is. Please refer to the layout other.xml in the example project for a full example. Again, note that it's the application namespace and not the actionbar namespace that must be referred like xmlns:app="http://schemas.android.com/apk/res/you.application.package.here".

In your activity

ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
// You can also assign the title programmatically by passing a
// CharSequence or resource id.
//actionBar.setTitle(R.string.some_title);
actionBar.setHomeAction(new IntentAction(this, HomeActivity.createIntent(this), R.drawable.ic_title_home_default));
actionBar.addAction(new IntentAction(this, createShareIntent(), R.drawable.ic_title_share_default));
actionBar.addAction(new ToastAction());

Custom actions

ActionBar comes with a convenient IntentAction that makes it easy to create action out of Intents. To create custom actions simply implement the Action interface and build your own like the Toast example below.

private class ToastAction implements Action {

    @Override
    public int getDrawable() {
        return R.drawable.ic_title_export_default;
    }

    @Override
    public void performAction(View view) {
        Toast.makeText(OtherActivity.this,
                "Example action", Toast.LENGTH_SHORT).show();
    }

}

Handle on click on the title

To handle on clicks on the title pass a android.view.View.OnClickListener to the method setOnTitleClickListener on the action bar. The View that is passed in onClick is the TextView that the title is assigned to.

actionBar.setOnTitleClickListener(new OnClickListener() {
    public void onClick(View v) {
        // Your code here
    }
});

Customization

Since the ActionBar is an Libary Project all resources will be merged to the project that referencing the ActionBar. The values in the main project will always be used before the default values of the ActionBar.

If you don't like the default colors that is defined in the colors.xml file simply override the default values in the main projects colors.xml file. To create a blue ActionBar create a colors.xml file that looks something like the one below. Note that we don't override the values for actionbar_background_item_pressed_start and actionbar_background_item_pressed_end since we decided to stick with the default values.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="actionbar_separator">#3A5FCD</color>
    <color name="actionbar_background_start">#3A5FCD</color>
    <color name="actionbar_background_end">#27408B</color>
</resources> 

The same can be done with the drawables, layouts and everything else that is located in the ActionBar project.

Is it stable?

Yes it is, but there's no guarantees. The api however is still not stable so please check all commits since the last pull. It might also be an good idea to depend on your own fork instead of this component directly. Eventually there will be more controlled releases but until then.

Are you using this widget?

Want to be featured in a gallery of apps using it? Then please send a screenshot and details of your app to Johan Nilsson.

Contributions

This widget wouldn't be the same without the excellent contributions by;

Want to contribute?

GitHub has some great articles on how to get started with Git and GitHub and how to fork a project.

Contributers are recommended to fork the app on GitHub (but don't have too). Create a feature branch, push the branch to git hub, press Pull Request and write a simple explanation.

One fix per commit. If say a a commit closes the open issue 12. Just add closes #12 in your commit message to close that issue automagically.

All code that is contributed must be compliant with Apache License 2.0.

Code Style Guidelines

Contributers are recommended to follow the Android Code Style Guidelines with exception for line length that I try to hold to 80 columns where possible.

In short that is;

  • Indentation: 4 spaces, no tabs.
  • Line length: 80 columns
  • Field names: Non-public, non-static fields start with m.
  • Braces: Opening braces don't go on their own line.
  • Acronyms are words: Treat acronyms as words in names, yielding XmlHttpRequest, getUrl(), etc.
  • Consistency: Look at what's around you!

Have fun and remember we do this in our spare time so don't be too serious :)

License

Copyright (c) 2010 Johan Nilsson

Licensed under the Apache License, Version 2.0

android-actionbar's People

Contributors

denravonska avatar ggrell avatar jakewharton avatar johannilsson avatar lvillani avatar obra avatar ohhorob avatar rickardpettersson avatar seansouthern avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-actionbar's Issues

Item drawables too large

The action bar item drawable icons are all appearing full height/width for me (they stretch to fill the height of the actionbar), rather than the smaller image with padding that is seen in the example.

Is this an xml thing? I took the code from the example nearly verbatim.

Importing Library in eclipse...!!!

I'm really new to Git and maven...!!! I downloaded the mimic-native-api branch because it had the latest commit...!!!
Looking at the folder I got to know that it is a maven project as it had a "pom.xml"...!!! Now I need to import it in eclipse because I am used to eclipse and have never used manen, so I installed maven on my ubuntu and ran command "mvn eclipse:eclipse" which made it a eclipse importable project...!!! The problem starts here, I don't want to add maven repo to my eclipse class path because I don't want any dependency on maven in using the library...??? Also I can't import the example because neither it has a pom.xml nor it is an eclipse project...!!! I tried copy pasting the code but I get lots of error...!!!

Can someone tell me how to make the library and example work in eclipse...??? I tried Googling for help and wasted my 2 days trying to figure it out on my own...!!! Please Help...!!!

Crash if press "Remove action" when no button in ActionBar

At first launch, I see there are 2 buttons in ActionBar.
I try to press "Remove Action" many times (> 2 times) and get a crash.

I found maybe because of OutOfBound exception in actionBar.removeActionAt(actionCount - 1);
removeAction.setOnClickListener(new OnClickListener() {
@OverRide
public void onClick(View view) {
int actionCount = actionBar.getActionCount();
actionBar.removeActionAt(actionCount - 1);
Toast.makeText(HomeActivity.this, "Removed action." , Toast.LENGTH_SHORT).show();
}
});
You should check if there is any button in ActionBar before remove it.

Cheers,
Btw, it's a great library. Thank your very much for your hard-working ;)

Error on Design Time

Hi,

I can run the Example application ok but at design time I have the following error: The following classes could not be instantiated:

  • com.markupartist.android.widget.ActionBar . Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse.

Any help???

Regards

overflow item

hi

how can i implement a overflow button in the actionBar?

for example. i will press a menu button in the actionBar and then it will open a sub menues?

thanks alot for great product :)

HomeLogo and Title overlap

Using the current version of the library, when Title and HomeLogo are used, the title overlaps the home logo.

Chines menu title not equally in itemspace

menu.add("ไธญๆ–‡1").setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add("ไธญๆ–‡2").setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add("ไธญๆ–‡3").setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);

when the activity use android:uiOptions="splitActionBarWhenNarrow",The three menuitem's space is not equally ,where can i fix the problem?

Text instead of Drawables

I'd like to have text as a button in the action bar, in addition to normal drawables. I did some initial research into doing this by drawing text onto a canvas then converting it to a drawable. It seems as though the action bar is expecting the integer for the drawable resource.

missing: actionbar_item_home

Latest version of mimic-native-api generates several errors in ActionBar.java.

    mHomeView = (FrameLayout) mBarView.findViewById(R.id.actionbar_home_view);

    // ...

    public Action findAction(int itemId) {
        if (itemId == R.id.actionbar_item_home) {
        // ...

    // etc.

actionbar_item_home is missing from the resources.

Title Text Color

I added a function to set a custom color for the title, but no matter what color it is set to, the color is displayed as black.

Action background does not change

Hi, I was using a custom background for ActionBar but when I add a custom action to my ActionBar like

actionBar.addAction(new FinishTagging());

where FinishTagging implements Action, the background of the area where the icon of this activity is shown still looks like the default one (which is red) even if I explicitly change it after the adding the activity with the statement below:

actionBar.setBackgroundColor(getResources().getColor(R.color.titlebackgroundcolor));

I wonder is it a known issue or is it just my fault?

Thanks in advance.

Add support for custom layouts

We need this to be able to style the action bar differently on different activities. Currently it's quite hard to have two different looking action bars in the same project.

Is there a way to cancel the selection from within onNavigationItemSelected?

There doesn't seem to be a way to override the current selection from within onNavigationItemSelected, for example if there was an error loading the class for an intent.

I tried calling actionBar.setSelectedNavigationItem, but calling that from onNavigationItemSelected does not change what appears in the action bar...mSelectedIndex is set to the "clicked" position after the function returns:

                                //Execute call back, if exists
                                if (mListCallback != null) {
                                    mListCallback.onNavigationItemSelected(position, mListAdapter.getItemId(position));
                                }

                                if (position != mSelectedIndex) {
                                    mSelectedIndex = position;
                                    reloadDisplay();
                                }

Note also that getSelectedNavigationIndex() returns the previous selection index if called from within onNavigationItemSelected...that may or may not be by design, it depends whether onNavigationItemSelected is meant as a prefix or postfix event. You could set mSelectedIndex before calling onNavigationItemSelected, so the behaviour of getSelectedNavigationIndex() is consistent inside and outside an onNavigationItemSelected function...however the current approach allows you to get what the selected item was "before" the onClick event, and use the itemPosition parameter to get the new selection index, so it is probably preferable this way.

Suggestion: allow onNavigationItemSelected to override the selection, e.g. check the boolean return value, and only update mSelectedIndex if onNavigationItemSelected returned true.

Not Actually an Issue but an Enhancements

First of all a big thanks to your component. I am currently developing my first android app with the help of your component.

I have added some enhancements and if you don't mind, you can review and probably add them

  1. Added home click listener

    public void setOnHomeClickListener(OnClickListener listener) {
    mHomeBtn.setOnClickListener(listener);
    }

  2. Added Action listener - a copy of your removeAction but this one is overriding the listener

    public void setActionOnClickListener(Action action, OnClickListener listener) {
    int childCount = mActionsView.getChildCount();
    for (int i = 0; i < childCount; i++) {
    View view = mActionsView.getChildAt(i);
    if (view != null) {
    final Object tag = view.getTag();
    if (tag instanceof Action && tag.equals(action)) {
    v.setOnClickListener(listener);
    }
    }
    }
    }

Example implementation

The setHomeOnClickListener will intercept the action before proceeding. Basically it will just validate if you want to discard changes made on the create screen.

    actionBar.setOnHomeClickListener(new OnClickListener() {        
        @Override
        public void onClick(final View v) {
            // TODO Auto-generated method stub
            AlertDialog.Builder builder = new AlertDialog.Builder(CreateActivity.this);
            builder.setMessage("Discard changes?")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       actionBar.onClick(v);       
                       CreateActivity.this.finish();                            
                   }
               })
               .setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                   }
               });

            AlertDialog alert = builder.create();
            alert.show();
        }
    }) ;

The setActionOnClickListener will intercept the action by first saving the data before proceding with the request.

    actionBar.setActionOnClickListener(saveAction, new OnClickListener() {          
        @Override
        public void onClick(View v) {
            //save data
            actionBar.onClick(v);
        }
    });

build .jar file

can you build .jar file? so i can reference in my android application directly.

How to change actionbar images dynamically

Hello ,

I am currently using this actionbar in my application. One thing i cannot do though is changing a image of a button on the action bar.

So the button on the action bar controls a viewflipper below. when the view changes in the viewflipper i want to the button in the action bar to change also .

Is there any way of programitcally changing the action button dynamically?

Clicking logo does not trigger onOptionsItemSelected

The documentation for ActionBar.NAVIGATION_MODE_STANDARD states:

    /**
     * Standard navigation mode. Consists of either a logo or icon and title
     * text with an optional subtitle. Clicking any of these elements will
     * dispatch onOptionsItemSelected to the host Activity with a MenuItem with
     * item ID android.R.id.home.
     */

...however this does not seem to occur in my app. The highlight colour is shown, but it does not reach either onOptionsItemSelected or onMenuItemSelected.

The same thing occurs in both NAVIGATION_MODE_STANDARD and NAVIGATION_MODE_LIST.

Note also that android.R.id.home is not resolvable in 2.3.3 (API level 10), it's only available since 3.0 (API level 11 or higher).

LongClick extension

I found the ActionBar project yesterday and have found it to be wonderful.

One of the problems I have will Android application is that the purpose of icon buttons is not always clean (eg. some of the Gmail icons).

For this reason I needed adapted ActionBar of the user can use a LongClick to get a textual description of the Action's purposes.

I am not Git skilled and my Eclipse has completely reformatted the source code so I cannot easily generated a short list of differences.

If you are interested in the feature then the to ActionBar.java are quite trivial and outlined below.

  1. There is an extended ActionBar.Action interface called "ActionBar.ActionPlus".
    public interface ActionPlus extends Action {
    public void performLongClickAction(View pView);
    }

  2. the class now implements "android.view.View.OnLongClickListener" and the supporting code is
    @OverRide
    public boolean onLongClick(View view) {
    final Object tag = view.getTag();
    if (tag instanceof ActionPlus) {
    final ActionPlus action = (ActionPlus) tag;
    action.performLongClickAction(view);
    return true;
    }
    return false;
    }

  3. Last peice of the ActionBar code change is addition of the following 4 lines in the inflateAction() method.

    labelView.setImageResource(action.getDrawable());
  •    if (action instanceof ActionPlus) {
    
  •        labelView.setLongClickable(true);
    
  •        labelView.setOnLongClickListener(this);
    
  •    }
    

A example to how I have used this is my application is :

        actionBar.addAction(new ActionBar.ActionPlus() {
            public void performAction(View view) {
                doOpenDrawer();
            }

            public int getDrawable() {
                return R.drawable.drawer_open;
            }

            public void performLongClickAction(View view) {
                UtilsNotify.show(MainMenu.this, R.string.action_open_drawer_description);
            }
        });

I'm not sure if this is a Best Practice implementation of how to extended the ActionBar functionality.

  1. A better solution may have been to use a function "public int getStringId();" instead of the long "performLongClickAction()" and then use "Toast" directly to display the text message.

  2. Also if it was a private library module (where I did not care about backward compatibility), I would have just extended the definition of the "Action"/"ActionAbstract" implementations to handle the mStringId member (as is currently done for the mDrawable member.

NB. for my own local copy I have now implement both the above suggestions.

android.view.InflateException

How do i resolve this..
Thanks

01-16 14:09:30.821: E/AndroidRuntime(601): FATAL EXCEPTION: main
01-16 14:09:30.821: E/AndroidRuntime(601): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.enterprise.app/com.enterprise.app.TestActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.markupartist.android.widget.ActionBar
......................
01-16 14:09:30.821: E/AndroidRuntime(601): at com.markupartist.android.widget.ActionBar.(ActionBar.java:57)
01-16 14:09:30.821: E/AndroidRuntime(601): ... 24 more

line #8= <com.markupartist.android.widget.ActionBar

<com.markupartist.android.widget.ActionBar
android:id="@+id/actionbar"

style="@style/ActionBar"

/>

Transition to searchbar

Add the possibility of creating a SearchAction that would change the aspect of the ActionBar, turning it into a configurable SearchBar. It would be good for those who don't need the standard search interface and want to build a custom one.

Bar buttons inherit the 'separator' color if not opaque

If a bar button's color is not opaque, the separator color shines through and affects the button color, making it impossible to have transparent buttons. I know this is because the separator color is applied as the background color of a RelativeLayout in the xml...a better method may be to have a 1px element inside the relativelayout, to which the bg color is applied.

Problems using ActionBar

I'm trying to use ActionBar as you're using it in the example provided

    final ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
    Intent i = new Intent(getApplicationContext(), HomeActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    actionBar.setHomeAction(new IntentAction(this, i, R.drawable.ic_title_home_demo));
    actionBar.setTitle("Home");

and I'm getting NullPointerException's for every element of the mBarView (inside ActionBar) when I try to use them. Don't know why.

Failed to inflate with mimic-native-api

Hi,
the example application crashes with Failed to inflate!

01-04 14:52:33.769: E/ActivityThread(2127): android.view.InflateException: Binary XML file line #7: Error inflating class com.markupartist.android.widget.ActionBar

I tried to run it on an Touchpad with Android 2.3.7 but had to compile for Android 4.0.

When trying to use actionbar in my project I also get errors like:
Couldn't resolve resource @style/ActionBar
You must supply a layout_width attribute.

Maybe I done something wrong?

Change image dynamically

Hey, This ActionBar is very useful for my project. thanks a lot.
I have a little trouble, and I read the same issue in Closed Issue, but didn't able to get the proper answer.

How do I change the image of button on onResume function of activity?
I'm showing dialog of notification, based on the user reply the button icon should be set.
It's not necessary to use onResume, if any other way to change the image based on dialog response is also okay.

starting an activity for result

I want to add buttons for the camera and gallery intents, but I need to use startActivityForResult for them. I changed the code around a bit, casted the mContext as an activity which seems to run the camera intent, but not the gallery intent. Also it's not delivering any return code to the HomeActivity, onActivityResult never gets called.

There must be some better way of doing this which I've missed completely, could someone please tell me how to add these two intent starters to the quickbar so that I can use their results in the mainactivity.

How to change ActionBar items Background.?

Hello Johannilsson,
The Library you provided is a very nice.
I have one issue with it , is,
I am Providing one image for the background of Actionbar,
Now when i am assigning Actionbar items to it , I am assigning it tranceperent images.
But a blur white background is gets generated behind those images.
is there any way to remove that white background from Actionbar items?
please help me to sort out . I had wasted almost 3-4 days on it.
you can mail me on [email protected]
Thanks .
Mahaveer

ThemeHolo for honeycomb

Hello,

I'm beginning with your great implementation of ActionBar. I have more a bug and a request.

You recently add Theme.Holo compatibility for >V14. I'm interested by have also compatibility for tablet (v11 and more).
If I modify source to change theme with V11, it works on Honecomb. The only problems that I encounter is that the menu button on the bottom disappear and I have no access to menu. It would be interesting to add on you ActionBar a menu button on the right, that open on a list the menu for android V11 to V13. (Similar to the ActionBar of Android)

This bug is due to compiled for target greater than V11, the menu button disappear on Honeycomb, instead I use the classic theme.

Thanks

Benuch

How to instantiate ActionBar in code without xml?

I need to dynamically instantiate the class ActionBar using parameters stored in the database.
The problem is that to create a new instance of the class ActionBar need an interface instance attributeSet and I could not any way to create this instance without the need for an XML.

AttributeSet attributeSet = ???;
ActionBar actionBar = new ActionBar(this, attributeSet);

Add Labeled Actions

Hi, not sure this could be an issue since i dont know how to create a request. Would be possible to add labeled actions instead of iconized actions? I have made some small changes on the code in my local box. I was able to achieve this, but for some reason I can only add one action, the second one does not apper on the action bar. If you want, I can send my code changes to you. Thank you

[Q] Does this use native action bar when run on 4.0...???

I happen to write an application which would be for 2.3 as well as 3.0 as well as 4.0...!!! I used the native-mimic-api...!!!
I want to know if this library would automatically use native action bar on 3.0 and above or not...!!!

The situation is like this, I have an activity in my application which has an EditText in it, now when run in 2.3 its all okay, but when i ran it in 4.0, there is a problem...!!! When I long press on EditText with some text in it, default action bar of android shows with cut,copy past option and my action bar slides down...!!! I would need that when the native action bar is shown, it shouldn't slide down, but should be replaced by that default one...!!!

Any solution...???

crash: removal of the actions from actionbar

I used "Remove Action" button to remove all the actions one by one.
it crashes when I tried to remove further, its because there are no more actions to be removed.
in this case the actionIndex = -1 and number of child nodes in actionView is 0.

below is the fix works great:

/**
* Remove a action from the action bar.
* @param index position of action to remove
* HashFold: no-op in case of removal of non-existent Action.
*/
public void removeActionAt(int index) {

    int childCount = mActionsView.getChildCount();
    //no-op in case of removal of non-existent Action.
    if(index < 0 || childCount < 1)
        return;

    mActionsView.removeViewAt(index);
}

I'm the first timer on github and so don't know the exact process to put the fix.

could you analyze the above fix and see whether it qualifies as a minor fix?

3 Errors after adding Library

I successfully implemented this on one of my android applications, and it works great! I added the library to another project and got errors immediately after adding it. Errors are as follows:

The method getDrawable() of type ActionBar.AbstractAction must override a superclass method (Line 181 of ActionBar.java)

The method onClick(View) of type ActionBar must override a superclass method (Line 104)

The method performAction(View) of type ActionBar.IntentAction must override a superclass (Line 197)

I can resolve this by removing the @OverRide associated with each issue, but I am curious why it worked on one project and not another.

ActionBar red underlines?

Sorry, for I figure this is a straight NOOB issue, but:

when i add the
ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
// You can also assign the title programmatically by passing a
// CharSequence or resource id.
//actionBar.setTitle(R.string.some_title);
actionBar.setHomeAction(new IntentAction(this, HomeActivity.createIntent(this), R.drawable.ic_title_home_default));
actionBar.addAction(new IntentAction(this, createShareIntent(), R.drawable.ic_title_share_default));
actionBar.addAction(new ToastAction());

on my project, the ActionBar term is giving me errors. I was told actionbar only works on Android 3.0+, is this true of your project as well or is ActionBar not coming up because i screwed up importing your other project as a reference/library

Alling logo to the rigth

What that i need modify to aling the logo to the right?Its apperead at center.
I have this code:

  ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);    
   actionBar.setHomeLogo(R.drawable.logo); 
   actionBar.setDisplayHomeAsUpEnabled(true);

dropdown background colors aren't visible

The action bar is using actionbar_background_dropdown_start and actionbar_background_dropdown_end for the background of the dropdown list itself, but that background isn't visible because each item's background is drawn above it.

(Well, I suppose it would be if you used a translucent color. :)

Specifically, right now it's using actionbar_background_item_pressed_start and actionbar_background_item_pressed_end for each item in the dropdown list.

This is because drawable/actionbar_list_item_background.xml is using actionbar_btn_normal and actionbar_btn_pressed for the state list.

Suggestion:

(1) Add drawable/actionbar_list_item_normal.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="@color/actionbar_background_dropdown_item_start"
        android:endColor="@color/actionbar_background_dropdown_item_end"
        android:angle="-90"/>
</shape>

(2) Add drawable/actionbar_list_item_pressed.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="@color/actionbar_background_dropdown_item_pressed_start"
        android:endColor="@color/actionbar_background_dropdown_item_pressed_end"
        android:angle="-90"/>
</shape>

(3) Modify drawable/actionbar_list_item_background.xml as follows:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item
        android:state_focused="false"
        android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/actionbar_list_item_normal"
        />
    <item
        android:state_focused="false"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/actionbar_list_item_pressed"
        />

    <!-- Focused states -->
    <item
        android:state_focused="true"
        android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/actionbar_list_item_pressed"
        />
    <item
        android:state_focused="true"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/actionbar_list_item_pressed"
        />

    <!-- Pressed -->
    <item
        android:state_pressed="true"
        android:drawable="@drawable/actionbar_list_item_pressed"
        />

    <!-- Default -->
    <item
        android:drawable="@drawable/actionbar_list_item_normal"
        />
</selector>

(4) Add the four new colors to the colors.xml file:

<resources>
    <color name="actionbar_divider">#8B1A1A</color>
    <color name="actionbar_title">#FFFFFF</color>
    <color name="actionbar_subtitle">#E0E0E0</color>
    <color name="actionbar_background_start">#8B1A1A</color>
    <color name="actionbar_background_end">#CD2626</color>
    <color name="actionbar_background_dropdown_start">#8B1A1A</color>
    <color name="actionbar_background_dropdown_end">#B02121</color>
    <color name="actionbar_background_dropdown_item_start">#8B1A1A</color>
    <color name="actionbar_background_dropdown_item_end">#B02121</color>
    <color name="actionbar_background_dropdown_item_pressed_start">#FF7F00</color>
    <color name="actionbar_background_dropdown_item_pressed_end">#EE7600</color>
    <color name="actionbar_background_item_pressed_start">#FF7F00</color>
    <color name="actionbar_background_item_pressed_end">#EE7600</color>
    <color name="actionbar_tab_bar_background">#999999</color>
</resources>

Note: you only need to add 2 colors if you don't want the list background colors to be configurable.

Must use Theme.ActionBar in ActivityManifest.xml

A heads up after updating the mimic-native-api branch on 2011-05-30:

If you get an error (e.g. "You must supply a layout_width attribute.") where the actionbar.xml is inflated, check your ActivityManifest.xml to make sure the activity in question is using the ActionBar style as its theme.

For example, if you have activity using this:

android:theme="@android:style/Theme.NoTitleBar"

...you will need to change it to this:

android:theme="@style/Theme.ActionBar"

You can remove the title bar with the "android:windowNoTitle" style item in any custom themes you set up, as is done for the OtherTheme in the example app.

It might be worth mentioning this in the readme or as a comment somewhere. :)

Crash when removing while no action availabe

The example crashes when the user is trying to remove the action bar when no action bar is shown (All them have been removed).

To fix this, when the user is removing, the number of the actions in the action bar should be checked:

case (R.id.remove_action): {
            int actionCount = actionBar.getActionCount();
            if (actionCount > 0) {
                actionBar.removeActionAt(actionCount - 1);
                Toast.makeText(HomeActivity.this, "Removed action." , Toast.LENGTH_SHORT).show();
            }
            break;

Error on Design Time

The problem is happening again...

Hi,

I can run the Example application ok but at design time I have the following error: The following classes could not be instantiated:

com.markupartist.android.widget.ActionBar . Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse.
Any help???

Regards

Can't set home logo

I want to display the action-bar such that I have my logo (png) and the title right next to it (like in the referenced app STHLM Traveling - Journey planner for Stockholm Public Transport). I am using this code:

    ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
    getMenuInflater().inflate(R.menu.main_menu_actionbar, actionBar.asMenu());              
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setHomeLogo(R.drawable.icon); 

The main_manu_actionbar.xml looks like this:

For some reason, the logo will never show up. Only the title appears on the left side and the action menu menu_report on the right side. Where is the logo?? Thanks.

Failed to inflate, again

Hi,

sorry to bother you again.
I'm still not able to add actionbar-mimic to my project.

01-05 12:36:44.130: E/ActivityThread(4830): android.view.InflateException: Binary XML file line #7: Error inflating class com.markupartist.android.widget.ActionBar

The graphical editor withmy main.xml says.
Couldn't resolve resource @style/ActionBar

Looking at your example I think i have to add some styles / themes to my project?
Can you please explain what I have to add and where?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.