Change logo that appears in Android ActionBar programatically - android

Is there a way to change the logo that appears in the ActionBar inside an Activity instead of listing it in the Manifest?
The reason I ask is I have an app for phones where I build a similar type of bar across the top with the launcher icon in the left corner similar to the ActionBar using an ImageView.
I also allow the user to change that image to one on their phone or on the internet. I am currently making the app work for tablets and would like to just use the ActionBar instead but can't figure out how to change the image based on the user. There is no method in the ActionBar class and I could not find a way to modify the icon or logo from the resources.
Anyone know if this is possible or could suggest something I could try?

Prior to the introduction in API 14 of the setIcon and setLogo methods that Jake mentions, you appear to be able to change the ActionBar logo by grabbing the view of android.R.id.home and setting a new drawable.
ImageView logo = (ImageView) findViewById(android.R.id.home);
logo.setImageDrawable(drawable);

API 14 introduced setIcon and setLogo methods.
As for 11 through 13 there's no easy way.
You could possibly use a custom navigation and hide the regular icon/logo by having your own layout mimic its functionality.
There is a homeLayout attribute in the action bar style which allows specifying an alternate layout resource to be used but it will always throw a ClassCastException since it is instantly cast to an internal class upon inflation (bug #21842).

Related

What would be a good way to show activity title without actionbar?

Im making an app for android, without actionbar.
What is best practice for showing titles without actionbar?
The best practice is basically never using an action bar. This gives you a complete device screen to play with.
You can use images or different text styles for showing the title. You can also use interesting icons.
To remove action bar -
Go to res > values > styles.xml
Here is an illustration of styles file -
You can use the Toolbar (it's like the action bar, but more flexible). For example, action bar needs to be on top of the screen, but toolbar can have place anywhere in the layout.
You title can be shown as text or a beautiful asset.
If, for some reason, you don't want to use the toolbar, you can think about something like having a scrollView with the title on top of it.
Use a regular LinearLayout with a TextView inside. Style according to your needs, and set the text in the xml, or programmaticaly using TextView's setText() method.

Designing action Bar in android or make it alone

how to make the bar in the top of the picture (see the link) (drawerbutton,"mes cercles",picture_pen)? by customizing the action bar or i make it manually?
https://drive.google.com/folderview?id=0B6Cz2zvfARSdOHJKSEppSzd6ZHM&usp=sharing
The ActionBar in that screenshot is custom-made. It is not built using Android's ActionBar controls. It appears that it was created using a RelativeLayout with a custom background, 1 button on each side and text in the middle of the layout. You can do this as well, however, it is considered best-practice to use Android's ActionBar, which can be themed partially. (Background, text color, buttons, logo, etc...)
Since Android's ActionBar is relatively new, you should use ActionBarSherlock, which adds compatibility to Android 2.x.
http://actionbarsherlock.com/
You can customize the actionbar in android to a very good extent , give it a solid / gradient background , customize the font face , add buttons , event give to different round corner values, also tabs are available , i suggest that method so you don't need plug-ins
the below two posts might be useful
android developers page / actionbar
Using the Android action bar (ActionBar) - Tutorial - Vogella

Benefits of native ActionBar vs custom implementation?

I would like to try and use the native Google ActionBar class for my application however, I would like to be able to change the left most image dynamically, disable the icon and center the title. I was wondering if this is possible of if I should implement my own ActionBar?
My reason for wanting to change the left most image (IE the navigation drawer indicator) is because I am using the navigation drawer but on some screens would like to display the up indicator instead.
Looking through the documentation for the ActionBarDrawerToggle, there is a method to enable/disable the navigation drawer icon (setDrawerIndicatorEnabled), when disabled it reverts to the home-as-up indicator.
Another option is to recreate the drawer in those specific screens you want the icon different and specify the new icon in the creation of the drawer, not sure if this would work though.
http://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html
Here is the android guide which explains how to do this, but allow me to give a brief overview.
You do not have to have the app icon as the leftmost icon so in certain pages you can disable it by specifying another "android:logo" item in the XML file, or by simply diabling it entirely.
The android logo, which is what you are talking about as the "leftmost item", can have an onClickListener() set for it which is how you can change it simply to an uparrow image which you can download from google.

Title Bar like that of Youtube app

I want this type of custom title bar
But can anyone tell me what the portion marked with red is made of? I mean are they tabs or image buttons or something else? Please don't give me links on how to apply a custom title bar, I already know it. But I don't know what the red-marked portion is (tabs or image buttons etc) And how can I have that vertical line between Search and Make Video option (in the portion that's marked red) I'm using Gingerbread.
I tried using search engines but how can I search when I don't know the name of the thing I want to search :s
They are called ActionBar Action Items. See: http://developer.android.com/guide/topics/ui/actionbar.html\
As for dividers, take a look at: ActionBar MenuItem Divider
You should to use ActionBarSherlock.
http://actionbarsherlock.com/
This is for add actionbar in devices android <3.x.

How Does Skype Do The Android View At The Top?

I am trying to find the name of the built in widget that is used to make the static bar at the top of the Skype app for Android. Does anyone know? I think it adds easy button functionality.
Also, how within that bar they have a button to change the user's status. It pops up a pretty bubble with an animation. Is this something built into a library or custom?
The action bar wasn't included until 3.0 as its the same app thats used for both tablets and smartphones, and on a tablet, the menu is still present, not shifted to where the action bar should be.
Its more likely they have each activities content in a scrollview, and a static layout pinned to the top of the page,
If you make your activities that will be using the top bar extend a base activity class that includes handlers for the static layout at the top of each page, and define the layout separately to be included in each activity's layout where it is required.
As for the bubble that animates out, it will be part of the layout but hidden, or not part of the layout, but inflated from xml pragmatically. i dont know what the exact animation is that makes it zoom in from the center though. The actual bubble will be another layout, wrapped in a FrameLayout so i sits nicely on top of the current activities layout.
Hope some of this was helpful
Check out ActionBarSherlock for a library that lets you easily implement action bar on pre-Honeycomb devices.
The static bar thar you are talking about is the action bar. It's included as standard in the version 3.0 of the API but you can also use libraries that provides you a very likely widget.
I use a modified version of GreenDroid library... You can also install the GreenDroid Catalog application from the Market to take a look.
Ah! of course you can change the color using styles!

Categories

Resources