How to add custom font to the action bar? - android

I wanted to know how to add my own custom font to the app name that appears in the action bar in android studio.

You can set CustomLayout in ActionBar
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = LayoutInflater.from(this);
View v = inflator.inflate(R.layout.titleview, null);
//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.title)).setText(this.getTitle());
//assign the view to the actionbar
this.getActionBar().setCustomView(v);
You can assign the custom font to textview by using setTypeFace()

I did this by just making an image of the app name with the custom font then displaying the image as the logo in the action bar. Much simpler.
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setLogo(R.drawable.app_logo);

Related

use android backAsUp with custom title bar

I have a custom title bar, a simple relative layout, that I set as the custom title bar of my activity. But at want the android BackAsUp icon < to show up as usual (i.e. to the left of my custom layout). How do I do that? here is my code so far.
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.my_title_bar, null);
this.getActionBar().setCustomView(v);
Update:
I have tried the answer at Remove Icon but have HomeAsUp in ActionBar they don't work. So one question, is order of setting those flags matter?
Adding the following combo solved the problem.
getActionBar().setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent)));
this.getActionBar().setDisplayShowHomeEnabled(true);

Customize actionbar in actionbarsherlock

I want to customize my actionbar like the Image shown below.
I am using Actionbarsherlock in implementation, as I have shown I will have a total of 5 icons, where 3 of them are centered and the other 2 are at the sides.
There are also separators added,
How do I add a style like this?
Just create a layout. As a separator you can use view with width of 1dp and your icons will be imageviews. Then set this layout to your actionbar.
You can add layout to your actionbar like that:
ActionBar actionBar = getSupportActionBar();
View actionBarView = getLayoutInflater().inflate(
R.your_layout, null);
actionBar.setCustomView(actionBarView);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
Then if you want to add onClickListener to your ImageView, you can do it like this:
ImageView imageViewOption = (ImageView) actionBarView.findViewById(R.id.image_view_option); //it's important to use your actionbar view that you inflated before
imageViewOption.setOnClickListener(...);
And if you don't want to have your application icon in actionbar then you can play with setDisplayXXX options. You can find more here: http://developer.android.com/guide/topics/ui/actionbar.html

How to display a custom view in the ActionBar?

I am trying to display a custom view in the action bar. I am using SherlockActionBar.
Here is my code. The custom view is never showing. What am I doing wrong?
View customNav = LayoutInflater.from(this).inflate(R.layout.my_layout, null);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setCustomView(customNav);
You must enable custom views first.
getSupportActionBar().setDisplayShowCustomEnabled(true); // missing in your code
getSupportActionBar().setCustomView(customNav);

How to do this in actionbar (2 vertical TextView)

Its posible to do this in actionbar sherlock? I know how set the icons but not the 2 textview in vertical layout posicion..This is a photoshop image
you can add custom view in action bar
ActionBar ab = this.getActionBar();
if(null!=ab){
ab.setDisplayShowCustomEnabled(true);
View cView =getLayoutInflater().inflate(<id>, null);
ab.setCustomView(cView);
}
The action bar features both a title and a subtitle. If you set both, both will appear on top of each other.
One thing to note is that they will be left aligned which is counter to your photoshoped image (which seems to be removed).

Can i take tab bar and custom title-bar in same Activity

I have Tab-bar and custom title-bar in same activity.In static mode am able to display tab-bar and custom title-bar in the same activity. But when i assign dynamic values to custom title-bar attributes it shows error as
AndroidRuntimeException: You cannot combine custom titles with other title features
Please provide any suggestions.
Thanks in advance
Try:
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
this.getActionBar().setDisplayUseLogoEnabled(true);
final LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View v = inflator.inflate(R.layout.header_bar, null);
//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.header_bar_title)).setText(this.getTitle());
//assign the view to the actionbar
this.getActionBar().setCustomView(v);
and make sure you do this before setContentView() method.

Categories

Resources