If i use default actionbar i can set home button to open and close drawerlayout with this code.
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
And it's work well.
But i dont't want default actionbar i want actionbar with customlayout.
When i use custom actionbar i don't know how to implement home button for open and close drawerlayout.
How to implement drawerlayout with custom action bar?
PS. I use custom actionbar because i want set title text to align center of actionbar, set text and text size to it's.
EDIT
thank you every body i can solve it's by use this.
getActionBar().setCustomView(R.layout.actionbar);
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
it's work well but the home button image change from app logo to app icon.
You can create custom Action bar like this ..
// gets actionBar reference ..
actionBar = getSupportActionBar();
// This sets custom layout to action bar
actionBar.setCustomView(R.layout.action_provider);
// this is how... .... you get id of layout defined
iv_d = (ImageView) actionBar.getCustomView().findViewById(R.id.action_menu);
Now just open you drawer on click of this icon using OnClick()
That's it .. you are good to go.
Related
I'm trying to customize the font in one activity action bar. I managed to do it by using this code during activity's onCreate:
if(getSupportActionBar()!=null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.secondary_toolbar);
TextView actionBarTitle = getSupportActionBar().getCustomView().findViewById(R.id.toolbar_title);
actionBarTitle.setText(R.string.new_payment_method);
}
The problem is that if I change the toolbar to a custom layout, the code lines which enables the arrow to let the activity to navigate to the previous activity doesn't work anymore. I'm stuck finding a way to modify the font in the action bar and showing the back arrow which allows me to navigate back, at the same time.
I try to hide ActionBar in Navigation View by using getSupportActionBar().hide() but it makes menu icon on top left dissapear too, like this :
I want it show like this :
Could someone give me some advice ?
No, you can't because the icon is part of ActionBar. You can create ImageView (or Button, ...) and place it at the top-left position and handle click event or use transparent ToolBar
Add a ImageButton and fix it's position to top left corner . And handle the click event of the button using OnClickListner ... Simple ...
I have just done it,for anyone need it, just create an ImageView and handle click event with this:
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.openDrawer(Gravity.LEFT);
I want to add title under the icon that as default appears when i create the navigation drawer .
like in red border
Its not possible if you use normal ActionBarToggle, you can provide your own custom layout in toolbar and add menu icon to it but back animation will not work. Also you will have to handle click events on the menu your self
I need add a image in between navigation button and drop-down in action-bar.How can I do this?
you need to call setIcon() it will change the icon
getActionBar();
ActionBar actionBar = getActionBar();
actionBar.setIcon(R.drawable.my_icon);
see this for more detail
I am using Custom Action bar. For which the code i am using is -
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getActionBar().setCustomView(R.layout.custom_home_action_bar);
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(
R.color.color_dark_blue)));
but when I use this code to customise my action bar, navigation drawer icon is not shown. When I comment these lines it is perfectly shown but then I cannot customise my action bar.How can i achieve both?
Thanks in advance
I got the solution. I used
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
instead of
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);