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();
}
Related
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 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);
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")));
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>
I would like to do an edit mode, in the style of the tablet gmail app.
If the user presses the edit button on the actionbar, than I would like to show him/her an action view, that has a done button on the left side, and a delete button on the right.
I have an example that works without actionbarsherlock here:
https://code.google.com/p/romannurik-code/source/browse/misc/donediscard
I would like to stick to actionbarsherlock, for compatibility reasons.
This is the way I solved it in onCreateOptionsMenu:
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.white));
getSupportActionBar().setIcon(R.drawable.white);
for (int i = 0; i < menu.size(); i++) {
menu.getItem(i).setVisible(false); }
getSupportActionBar().setDisplayHomeAsUpEnabled(false); does nothing, so I had to set the home icon to a white 1x1 pixel drawable.
I also had to set the background color of the actionbar, as the actionview's background color. If I had not, than the 1x1 home icon would have padding around it, and the original background color would be visible around the white home button.
Anyone got a better solution for this?
edit:
I also had to change the style:
<style name="Theme.Styled" parent="Theme.Sherlock.Light">
<item name="android:homeAsUpIndicator">#drawable/white</item>
<item name="homeAsUpIndicator">#drawable/white</item>
</style>
Also..settings android:homeAsUpIndicator increased my min api level from 8 to 11 which is also an issue.
If you're on API level 14 or above and are not using ActionbarSherlock, this code in onCreateOptionsMenu will disable the up button, remove the left caret, and remove the icon:
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(false); // disable the button
actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}
You were almost there. To hide the icon/logo completely, use setDisplayShowHomeEnabled(false). The call you're using just removes the little arrow that indicates that the icon acts as an "up" button also.
This worked for me, though its a slight change in the above mentioned solution
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(false); // disable the button
actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}
Though it's an older post, I would like to share an answer which worked for me.
To hide the UP button in actionbar, use the following in OnCreateOptionsMenu:
if (getSupportActionBar() !=
getSupportActionBar().hide();
}
To remove the UP button in actionbar, use the following in OnCreateOptionsMenu:
if (getSupportActionBar() !=
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
I hope it will help newbies.