Subtitle below logo on actionbar android - android

I'm trying to place a logo that will act as the actionbar title and then have dynamic fragment based subtitles with text below.
Can you either set text below logo or the title as an image?
Is it possible?
Thanks!

ActionBar does not provides APIs for setting title as an image, you could try find the actual TextView in layout but I would not recommend that due Android fragmentation. It will not work on all devices.
You can however use a custom view in ActionBar, you will have to call
getActionBar().setDisplayShowCustomEnabled(true);

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.

appcompat 21 logo as back button

After update sdk to 21 version logo doesn't display. I display logo using following code:
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(R.drawable.ic_launcher);
The code looks:
http://i.stack.imgur.com/fAWIx.png
This code:
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.drawable.ic_launcher);
Looks:
http://i.stack.imgur.com/hkYqa.png
This code:
actionBar.setDisplayHomeAsUpEnabled(true);
Looks:
http://i.stack.imgur.com/Ssw2A.png
My logo doesn't display as back button.
How me make old style as here? http://i.stack.imgur.com/BKOz4.png
Note: Sorry, I didn't notice similar questions. =(
Per the Toolbar documentation:
A title and subtitle. The title should be a signpost for the Toolbar's current position in the navigation hierarchy and the content contained there. The subtitle, if present should indicate any extended information about the current content. If an app uses a logo image it should strongly consider omitting a title and subtitle.
In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.
However, if you want an application icon, setLogo() is indeed the correct method.
Here's what worked for me if using an icon
actionBar.setIcon(R.drawable.ic_app_icon);
actionBar.setDisplayShowHomeEnabled(true);
Or, if you want a wider logo
actionBar.setLogo(R.drawable.ic_app_logo);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayUseLogoEnabled(true);

Customize the up button on ActionBar to include title

I've been working with ActionBar for a while, but was constantly frustrated by its customizaton work. Also I've been playing with ActionBarSherlock and ActionBarCompat but finally get down to the later one.
I saw many apps combining the leftmost up button with the title into one clickable button on a ActionBar. How can that be achieved without supplying a custom layout for ActionBar? Is that a way to customize only the up button to include the title as well?
Thanks in advance!
The up button is an ImageView not button. So you can not apply text using setText();
You can set an image with text to that ImageView.
Sample code:
getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setIcon(R.drawable.YourImage);
OR
getActionBar().setDisplayShowHomeEnabled(true);
ImageView imgHome=(ImageView)findViewById(android.R.id.home);
imgHome.setImageResource(R.drawable.YourImage);

How to make actionbar tab menu with text below the icon?

I have been trying to figure out how to make an actionbar tab menu like the one pictured below. How can I make my tabs display the icon above the text as shown here? When I implement it, it displays the icon to the left of the text. Is there something akin to the compund drawable feature of TextView (android:drawableTop) I can use for the tab?
I am using a custom XML for the Main bar, and actionbarsherlock.
that is the old android tabs view, the new ones have the text on the side next to the image

Change logo that appears in Android ActionBar programatically

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).

Categories

Resources