I am able to do this but I now can not click the logo. It doesn't fire onOptionsItemSelected()..
actionBar= getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setTitle("");
actionBar.setLogo(R.drawable.logo);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(true);
if i set actionBar.setDisplayHomeAsUpEnabled(true); the arrow shows up. I have found a clone of this question, on SO but no one answered it correctly. Someone suggested using a transparent image for teh arrow but how do I override that?
I got it, use
setHomeAsUpIndicator()
Like this:
ActionBar actionBar = getSupportActionBar();
actionBar.setHomeAsUpIndicator(R.drawable.logo);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
Related
as you can see in the picture below, the white space lays between status bar and actionbar. I normally include android.support.v7.widget.Toolbar with TextView and then I set supportActionbar in MainActivity.
This bug happens only on Sony phone with android 6.0
Try this code
ActionBar actionBar = getActionBar();
if(actionBar !=null)
{
actionBar.hide();
}
I want to add the application icon in the actionbar for all the activities in my application and on the icon click , I would like to navigate to the home page of my application.
I tried with the following code in onCreate
ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setHomeButtonEnabled(true);
Now the application icon is coming in the actionbar , but on clicking it, onOptionsItemSelected is not getting called. But if use actionBar.setDisplayHomeAsUpEnabled(true) instead of actionBar.setHomeButtonEnabled(true) , onOptionsItemSelected is getting called with item.getItemId() . Below is the code snippet
ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
The documentation says using both setDisplayHomeAsUpEnabled and setHomeButtonEnabled , onOptionsItemSelected will be called and the only difference is the up arrow. I dont need the up arrow in the actionbar, I only require the application icon. How can that be done?
My minSdkVersion 14 and targetSdkVersion 21.
From http://developer.android.com/reference/android/app/ActionBar.html#setHomeAsUpIndicator(int)
You can use:
actionBar.setHomeAsUpIndicator(R.drawable.ic_launcher);
actionBar.setDisplayShowHomeAsUpEnabled(true);
and this should replace the back arrow with your icon
you can use this:
Toolbar toolbar = (Toolbar) findViewById(R.id.myToolbar);
toolbar.setNavigationIcon(R.drawable.ic_back);
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
finish();
}
});
You can use :
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
fist code shows left arrow on toolbar and second code lets you to put your icon
I am setting up my Toolbar in my main activity and trying to change the background color with different fragments.
So basically, I am trying to access the Toolbar object inside fragment and set different background color.
Few things which I have tried to do is :
Access toolbar like:
((ActionBarActivity)getActivity()).getSupportActionBar().setBackgroundColor(XXX);
But I am unable to access the setBackgroundColor function inside fragment. It is perfectly working inside the Main Activity.
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
or
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));
Have a look This or This
It is very easy to change the ToolBar, Actionbar color.
ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
or
ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));
I have an ActionBarDrawerToggle in the ActionBar. My action bar also has a custom view on it. The draw toggle and custom view both appear on KitKat (4.4) API 19
However, on lower versions (for example 4.1 API 16), the custom view in my action bar completely obscures the drawer toggle.
Working fine on 4.4 (Google Nexus 5):
How it looks on 4.1 (Google Nexus 4) (Notice the drawer missing on the left):
Wondering what can I do in this situation? Has anyone encountered this problem?
(Please note: I am not using actionbar sherlock, just the default one)
Thanks!
it works for me
getActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("yourcolor here"))); //$NON-NLS-1$
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ActionBar actionBar = getActionBar();
getActionBar().setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
// actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
// getActionBar().setIcon(R.drawable.ic_navigation_drawer);
// navigation icon on actionbar
actionBar.setHomeButtonEnabled(true);
actionBar.setIcon(null);
View actionBarView = inflator.inflate(R.layout.actionbar_custom_layout, null);
getActionBar().setCustomView(actionBarView);
In my application a have an ActionBar with Tabs as navigation mode. I also use a custom View which adds another "line" to the ActionBar. Setup looks like:
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.ab);
Typeface font = Typeface.createFromAsset(getAssets(), "cs_regular.ttf");
TextView title = (TextView) actionBar.getCustomView().findViewById(R.id.tvActionTitle);
title.setTypeface(font);
The problem: I do not want an icon to be shown, but when I use actionBar.setDisplayShowHomeEnabled(false); my custom layout gets placed BELOW the Tabs and I need it to be above the Tabs in the ActionBar. Setting it to true places the layout as I need it, but shows the unnecessary icon.. any suggestions?
I assume by icon you mean the app icon. You can essentially make it invisible using styles. Add this to the style your Activity is using:
<item name="android:icon">#android:color/transparent</item>