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.
Related
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
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
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:
I'm making an android app in Eclipse. I want to place a text or icon in the action bar, but when I am writing in menu.xml, which looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/createnew"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:title="CREATE"/>
</menu>
it puts it in the options menu. I want to separate it.
I see this in the app when I run it:
(sorry can't post pictures because I don't have enough rep)
I want to CREATE next to the option menu like this for example:
Since you are using the AppCompat Actionbar, you need to use a custom namespaced showAsAction attribute.
It should look something like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/createnew"
android:orderInCategory="1"
yourapp:showAsAction="ifRoom"
android:title="CREATE"/>
</menu>
Note that this uses yourapp:showAsAction instead of android:showAsAction. This is because the showAsAction attribute is not available on pre-Honeycomb devices and is provided by the support library.
For more information, read the Action Bar developer guide.
It's caused by this line
android:showAsAction="ifRoom"
That tells Android to put it up there if it's going to fit nicely. If you want it up there no matter the fit use
android:showAsAction="always"
I am using the actiobarcompat sample in my application and I am trying to implement search for pre 3.0 devices.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_search"
android:orderInCategory="1"
android:title="#string/menu_search"
android:icon="#drawable/ic_home"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
</menu>
On Honeycomb+ this works fine, the searchview widget appears in the actionbar. What I am trying to do is have a second menu XML so I can fall back to the old search activity way of doing it. However, there is no such thing as menu-v11 folder as the menu folder is essentially menu-v11 because that is the version it started supporting this.
My question is, using the actionbar compatibility sample, is there a way to declaratively add an alternate button for pre-honeycomb?
Can you please be more specific about what you are trying to achieve?
It it's about calling different activities depending on API version, the action bar has nothing to do with that.
You analyse API version in onOptionsItemSelected and act accordingly.
If you want different menu items depending on API version, just create a folder menu-v11 (or menu-v14) and put
version-specific xml-s- there.
BTW, I use com.android.actionbarcompat and it works great for me!