Android Navigation drawer custom icons - android

I've currently been looking into the navigation drawer of android and see the example code from android they use.
When starting a new project and selecting the navigation drawer activity. It gives basic structure which is great.
From this I see the icons used in the navigation drawer are android default. I wanted to see if possible to add my own png for icons. So far my code (in activity_main_drawer) is
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_connect"
android:icon="#drawable/icon_menu_connect_24"
android:title="Connect" />
<item
android:id="#+id/nav_settings"
android:icon="#drawable/icon_menu_settings_24"
android:title="Settings" />
<item
android:id="#+id/nav_help"
android:icon="#drawable/icon_menu_help_24"
android:title="Help" />
</group>
the _24 at the end of the name is just the 24pixel size indication.
Now after running this code all i get appear in my navigation drawer is square blocks and not the image.
Reason for using own png rather than android default, is looking at the defaults there was no images indicating what i wanted.
Appollogies if question has been posted before and thanks in advance

I have found the issue. I found that the image used in the menus need to have a transparent background. The images I was using did not get saved in that format and thus showed as a grey block. So although it gave a preview in the left hand margin in the XML file, it still was not in the right format
Using image asset to generate the icons was more efficient than lots of .PNG files

Related

Icons brooken and see like they are grayed out

I have a strange bug.
I have image as vector asset. It is created correct and see like:
I'm using it like menu icon on drawer:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/about"
android:icon="#drawable/ic_about_us"
android:title="#string/navigation_about" />
</group>
</menu>
But in device it looked broken:
Do you see images on the background? It's vector assets too, but they works fine. I place it from code.
I have the similar problem with ViewPager icons. It seems like only icons are broken. So i have two vector assets:
I set this icons two different way(specially):
layout_tab.getTabAt(0)?.icon = activity?.getDrawable(R.drawable.ic_type_bird)
layout_tab.getTabAt(1)?.setIcon(R.drawable.ic_hints)
And then i see:
One:
Two:
What is going on, why my assets broken?
Your assets are not broken, it is just that the navigation drawer automatically applies a color filter to the icons which makes them appear gray. It is similar for the tabbar (as it is trying to show the state)
The answer here shows how to stop this

Arrow missing from share icon within action bar

After creating a menu for my action bar. The little arrow doesn't appear next to the share icon and I'm not sure why this has happened or if it's intentional based on my code.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_info"
android:title="#string/information"
android:icon="#android:drawable/ic_menu_info_details"
app:showAsAction="ifRoom"/>
<item android:id="#+id/action_share"
android:title="#string/menuitem_share"
android:icon="#android:drawable/ic_menu_share"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
app:showAsAction="ifRoom"/>
<item android:id="#+id/action_preferences"
android:title="#string/menuitem_preferences"
app:showAsAction="never"/>
</menu>
After viewing images of similar menus online, I noticed that little arrow (in this screenshot).
How can that little arrow be added to the share icon?
As far as I know, every new project you create in Android Studio uses the Material design (introduced with Android 5.0 Lollipop) with AppCompat themes. It is designed to show up on every compatible device thanks to Support Library (even on pre-Lollipop devices), and ActionBar menu items created when you are using Support Library looks like on the first image.
As far as I also know, I've seen this kind of arrowed Share button on the second image last time on a 4.x device. So I think you could re-create this kind of Share button if you would not use any theme and let your pre-Lollipop device to do the work with the ActionBar.
I've tried to recreate this behaviour by your code above, without luck. But then I opened the ApiDemos app which is on every Android Studio emulator image and shows a lot of functions built up in Android, for example ActionBar functions. There I saw that Share button looks differently on different API levels.
Android 4.4 KitKat:
Android 5.0 Lollipop:

Android: use built-in icons or download icon pack

I wonder if I should use the built in version of Google's icons for menu items or if I should download the icon pack instead?
Here's the default XML for my menu. It's using the built-in icons but the visual results looks a bit odd.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ParkItemActivity">
<item android:id="#+id/action_remove"
android:title="#string/action_remove"
app:showAsAction="ifRoom"
android:icon="#android:drawable/ic_menu_delete" />
<item android:id="#+id/action_save"
android:title="#string/action_save"
app:showAsAction="always"
android:icon="#android:drawable/ic_menu_save" />
</menu>
But if I use the icons from the Material-Design-IconPack, then it looks like this. But is there a recommended way? Remark: Can't find the trash-icon in the new icon-pack. And the delete/remove is a simple minus symbol.
android:icon="#mipmap/ic_remove_white_48dp"
android:icon="#mipmap/ic_save_white_48dp"
Yes you are right, default drawable icons present in the android sdk doesn't scaled up according to the material design. Android sdk by default is not supported with material icons, instead of that you could make use of appcompat-v7 support library, which has few materials icon by default like copy, paste, clear, search, back, menu icons respectively.
To use appcompat-v7 icons in your xml
#drawable/abc_ic_menu_paste_mtrl_am_alpha
Note: Only few icons are listed out in appcompat-v7. You don't have any other options without using Material-Design-IconPackonce if you want to use specific other icons.
I reccomend you to find icons you would like to use and if you use Eclipse, you can navigate: Right-click your project -> New -> Other -> Android Icon Set. Don't forget to check "Action Bar Tab Icons" and you will be able to generate icons correctly scaled for actionbar.

Actionmenu: Show Title AND Icon

I use this code in my menu.xml:
<item android:id="#+id/physics"
android:icon="#drawable/ic_action_***"
android:title="#string/physics"
android:orderInCategory="2"
android:showAsAction="always"/>
Now my Icons aren't very much saying about the button they stand for.
So I wan't display them AND the title.
After long google research I found this on #stackoverflow:
Android Menu Icon with Title : Title doesn't display
But it's about the icons. I downloaded my icons already in the right size and put them in the right folder.
And I don't have problems with my icons, they are showing great, but when you see a line chart, you don't automatically think of physics, do you?
Any idea, how to display both? I also added a sting, it doesn't show up (is it even possible?)
Any idea, how to display both?
Replace:
android:showAsAction="always"
with:
android:showAsAction="always|withText"

Android: Margin between ActionBar icon and Navigation dropdown menu changes when you click search

I have the following setup:
So you can click on the search icon for the action bar to turn into a search bar. Pretty standard:
So if you're done searching you can click the Home icon to make the bar go away:
But when you go back, the navigation dropdown menu is shifted to the right quite a bit:
I can't really figure out what is happening here. The first thing I did was make a brand new app and recreate it (which is what you see below) to make sure it wasn't an issue with styles or themes I'm using in my main app. That didn't help the problem. I'm using ActionBarSherlock, so the next thing I did was rebuild the project using Google's official Action Bar API. That didn't make a difference either.
Does anyone have any ideas? I'll provide any code you guys think could help, but I took the implementation pretty much straight from Google's docs about it. Thanks!
EDIT: Adding some before-after images with layout borders visible (dev options feature in 4.1+)
BEFORE:
AFTER:
I've also included the menu XML:
<?xml version="1.0" encoding="utf-8"?>
<item android:id="#+id/abm_search"
android:icon="#android:drawable/ic_menu_search"
android:showAsAction="always|collapseActionView"
android:actionViewClass="android.widget.SearchView" />
<item android:id="#+id/abm_location"
android:title="Stuff"
android:showAsAction="never" />
<item android:id="#+id/abm_radius"
android:title="More Stuff"
android:showAsAction="never" />
<item android:id="#+id/abm_settings"
android:title="Other Stuff"
android:showAsAction="never"/>
Found out the problem. I had given the action bar a title of "". Instead, if you gave the action bar this display option:
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME);
it fixed the problem. Hope this helps someone else.

Categories

Resources