johannilsson / android-actionbar Goto Github PK
View Code? Open in Web Editor NEWDEPRECATED Android Action Bar Implementation
DEPRECATED Android Action Bar Implementation
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.
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
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 ;)
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).
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.
Hi,
I'm using android-actionbar as a library as well as GreenDroid(https://github.com/cyrilmottier/GreenDroid).
After adding both of them as libraries, Eclipse warns that .../android-actionbar/actionbar/res/values/attrs.xml:19: error: Attribute "title" has already been defined
How could I fix it?
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...!!!
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.
I want the tabs on bottom of screen,how can i do?
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...???
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 :)
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.
can you build .jar file? so i can reference in my android application directly.
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. :)
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.
sometime i need change the icon of exsit actionbar, like change privacy.
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.
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
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?
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?
Hi,
I can run the Example application ok but at design time I have the following error: The following classes could not be instantiated:
Any help???
Regards
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.
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
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"
/>
Ability to add progress bar that indicates progress as an alternative of ProgressBarIndeterminate.
I made a new one: https://github.com/STALKER2010/ActionBar
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);
The library still needs to support NAVIGATION_MODE_LIST as described here:
http://developer.android.com/guide/topics/ui/actionbar.html#Dropdown
Support for list navigation exists in ActionBarSherlock (https://github.com/JakeWharton/ActionBarSherlock) but this library doesn't seem to provide an implementation for that navigation mode?
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?
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.
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.
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
Using the current version of the library, when Title and HomeLogo are used, the title overlaps the home logo.
I suggest change the IntentAction to Action for setHomeAction, then you can give a Action implement for HomeAction .
What's the minimum api requirement?
Action Bar need Android 3.0 at least from this
http://developer.android.com/guide/topics/ui/actionbar.html
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
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!
Example code;
<com.markupartist.android.widget.ActionBar
android:id="@+id/actionbar"
title="@string/some_title"
style="@style/ActionBar"
/>
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.
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.
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.
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);
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.
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.
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.
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.
There is an extended ActionBar.Action interface called "ActionBar.ActionPlus".
public interface ActionPlus extends Action {
public void performLongClickAction(View pView);
}
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;
}
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.
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.
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.
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
Added home click listener
public void setOnHomeClickListener(OnClickListener listener) {
mHomeBtn.setOnClickListener(listener);
}
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);
}
});
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?
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;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.