I want to remove the left arrow from the action bar and only icon and title needed.
My code:
getSupportActionBar().setIcon(R.drawable.logo);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(R.string.dashboardtitle);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
But this doesn't remove the left arrow . Any help!!
According to specification android specification:
To enable the icon for up navigation (which displays the "up" indicator next to the icon), call setDisplayHomeAsUpEnabled(true) on your ActionBar:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
...
}
So you should set actionBar.setDisplayHomeAsUpEnabled(false);
UPDATE:
I test next code with ActionBar sherlock and it's work. There is no back arrow:
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(R.string.about_event_location);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
You need to add this to your actionBar theme. You can replace arrow image with your own image which can be transparent
<item name="android:homeAsUpIndicator">#drawable/action_arrow</item>
getActionBar().setHomeAsUpIndicator(R.drawable.action_arrow);
Where action_arrow is a 25x10px transparent png.
Same code for sherlock would be:
getSupportActionBar().setHomeAsUpIndicator(R.drawable.action_arrow);
#vivek: works great. I do not recommend to use #android:color/transparent as Tim Cooper said, because the Title is aligned to the left. So a empty image is better
In AndroidManifest.xml
remove the below code, which will remove back button from your ActionBar
android:parentActivityName=".Main.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Main.MainActivity" />
Just keep it like below:
<activity
android:name=".YourActivity"
android:label="#string/your_activity_label">
</activity>
Related
I'm working with actionBar in android and the default logo is not showing. So I have added this code to show the Logo in my onCreate method in MainActivity.
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setLogo(R.drawable.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
Why is the logo has a wide space causing the title to not be seen?
Please help. Thanks.
This is very simple to accomplish
If you want to change it in code call
setTitle("My new title");
getActionBar().setIcon(R.drawable.my_icon);
And set the values to whatever you please.
In Manifest XML:
<activity android:name=".MyActivity"
android:icon="#drawable/my_icon"
android:label="My new title" />
To enable the back button in your app use
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
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
with below code , i make a Transparent Actionbar for my FragmentActivity & all fragments:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#64000000")));
setContentView(R.layout.main_slidemenu);
.
.
.
}
But i have a problem with this , i need to SlideMenu just open under actionbar , but it open i all of layout.
You are probably looking for the ActionBar overlay mode.
Enable it for a single Activity by calling requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); before setContentView(). Or in a theme by setting android:windowActionBarOverlay to true.
if you've used SlidingMenu library you could use :
setSlidingActionBarEnabled(false);
but according to the link you've provided you have used NavigationDrawer , with NavigationDrawer i think you could use layout_marginTop for your NavigationDrawer in it's layout xml and for better achievement , get your ActionBar height dynamically then set margin to that.
and also try removing line below:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
i've used NavigationDrawer before without setting Layout_marginTop and Window.FEATURE_ACTION_BAR_OVERLAY and its below my ActionBar.
So I have this under my Activity's onCreateView()
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
And my manifest looks like this
<activity
android:name="com.example.nfcproducttracing.ProductTracer"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Light"
android:launchMode="singleTask">
What I have achieved is have my application with Tabs, but no TitleBar. However, during application launch I can briefly see the TitleBar before it disappears, and I do not want that.
What am I supposed to do? When I set my activity theme to anything related to NoTitle, getActionBar returns null and the app crashes.
If I understand correctly your questions, you can use the requestWindowFeature(Window.FEATURE_NO_TITLE) from your activity.
Flag for the "no title" feature, turning off the title at the top of the screen.
Not really sure but have you tried this:
getActionBar().setTitle("");
It will set a blank title for your ActionBar.
You can try using getSupportActionBar() instead.
this is from android.support.v4.app.actionbar, not from android.app.actionbar!
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.