I'm implementing NavigationDrawer with ActionBarSherlock and now I'm trying to implement custom icon for opening and closing the drawer. I already set my own icon (white) but I'm not able to get rid of that grey default icon.
in onCreateOptionsMenu I'm doing this:
getSupportActionBar().setDisplayShowTitleEnabled(false); // does not display activity title
getSupportActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.actionbar_background)); // blue background
getSupportActionBar().setIcon(R.drawable.side_menu_button); // white icon
The picture shows difference when navigation drawer is closed (first) and open (second picture).
Is there any way to do it programmatically? Or is there even some way to do it? I hope it is.
Thank you.
EDIT: This is what I'm trying to achieve:
What you are currently doing is setting the icon on the ActionBar, which is different from setting the icon of the ActionBarDrawerToggle, which is what you want to be dealing with. If you look at the documentation (http://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html) and find the constructor, you'll see there's a place to specify a custom Drawable to be used by the toggle.
Related
I'm new to Android development. I get that a NavigationView is an AppBar (i think). What makes these two different? I want to create a custom "appbar/toolbar" with a centered logo and menu/settings button in the top right corner (instead of the standard left) which reveals a drawer.
I was going to ditch the built in appbar/toolbar all together and just create my own somehow and include button overlay which displays a drawer.
What would you do? Navigation view, app bar, or custom toolbar from scratch? I don't know what the standard is or what is acceptable. What is the difference between a navigationview and appbar. Thank you.
edit: I'm slowing realizing that an appbar is one feature within a navigation view, among others like a drawer layout, menu items etc... i think.
1. NavigationView
By using NavigationView, we can bind the menu directly with NavigationView. This is the benefit of the NavigationView. No need to create ListView and adapter with navigation drawer. By default we can get selector of item click. With menu we can change the color of icon of selected menu.
For more details :
1.https://developer.android.com/reference/android/support/design/widget/NavigationView.html
http://www.technotalkative.com/part-4-playing-with-navigationview/
2. AppBar
Appbar is for toolbar with scrolling effect. We can easily give the material design effect.
For more details :
1.https://developer.android.com/reference/android/support/design/widget/AppBarLayout.html
how to create display toolbar change icon in tab layout as in Line Messenger ?
I've been trying to figure out, but it never worked.enter image description here
Sorry my english is not good . Thanks !
You can use invalidateOptionsMenu(), and the onCreateOptionsMenu() method will be recalled, so you can decide to inflate another XML-Menu layout.
Good luck
When SearchDialog is called, it have a white background.
There's a way to change the background color, and also remove the up button with the icon near to it?
I don't use the SearchView, i use the search dialog because i need it also in android pre 3.0
Thanks
I want to use android menu function.
And I already set onPrepareOptionsMenu(),
and set the content.
But I have problem, that my pad has no menu icon to click.
Do I need to set anymore?
Since Android 3.0 (Honeycomb), that was made especially for tablets, there is no more hardware menu button (but phones still got one), so to use ActionBar for tablets, You could follow this tutorial:
http://www.dreamincode.net/forums/topic/274639-android-actionbar-tutorial/
and read this too:
http://developer.android.com/guide/topics/ui/actionbar.html
The overflow option menu icon (looks like 3 dots) at top-right corner will not appear if your device has a hardware menu key.
Your device must be at least on 3.x.
In tablet you have implement ActionBar in your activity. For enable and use of ActionBar you must have to use Titlebar for your activity. Just create the Theme in style.xml having Title bar and store in value-xlarge dir for large screen. And get the ActionBar object by using this getActionBar().
Note: You must have to use API 11 or above if you have minSDK below 11 then you have check version of OS
Instead of using
onPrepareOptionsMenu(),
which is for updating text and other thing once menu option is created, use
public boolean onCreateOptionsMenu (Menu menu)
and selection of menuitem can be achieved by
public boolean onOptionsItemSelected (MenuItem item)
Many examples can be found for menu creation,updation and selection.
If you set android:targetSdkVersion bigger than 10 and you are using theme NoTitleBar in the devices which are running Android 3+ and which don't have menu button there won't show a software menu button next to back button. If you want that option to be enabled set your targetSdkVersion to 10 and test i your device if there will show the software menu button.
Achieving a true "dropdown" effect (as seen in Adobe's Photoshop Mobile app for Android, image below) has proven challenging using Androids built-in methods.
As others on Stackoverflow have told me, editing the style of a dropdown list view of an Android spinner is limiting.
How is this dropdown effect done?
(I can't seem to get an image to show, so here's a link: Adobe Photoshop Mobile for Android
After viewing the Adobe slideshow I think the way I would attempt to get that to work, using the Android Java SDK, would be to create a ListView object with a transparent background, and then dynamically hide/show it in that position when the menu button is clicked by setting the View's visibility to VISIBLE or GONE.
Getting a ListView to be transparent shouldn't be that difficult. I'd look into AbsoluteLayout to get it to hover over everything in that spot.
Another option might be to display the ListView in a custom Dialog that you've written, again positioning it in that exact spot on the screen so that it looks like a menu extending from the button that was clicked.
It's probably done using low-level draw functions.