Best way to add android standard icons in Xamarin

10,368

Normally I use 36dp images as Icons in toolbar. You can download the 36 dp variant from the dropdown at bottom from Material Design Icons. You can download that and replace in menu as

<menu
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">
<item
  android:id="@+id/action_search"
  android:orderInCategory="200"
  android:title="Zoeken"
  android:icon="@drawable/ic_search_white_36dp"
  app:showAsAction="ifRoom|collapseActionView"
  app:actionViewClass="android.support.v7.widget.SearchView"
  android:inputType="textCapCharacters"/>
</menu>

Also you can add other custom Icons (36 dp icons for clarity) to your toolbar as below

 <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/transparent"
            android:minHeight="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
            <Button
                android:id="@+id/editButton"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_gravity="right"
                android:background="@drawable/ic_edit_white_36dp"
                android:layout_marginRight="16dp"
                android:visibility="gone" />
        </android.support.v7.widget.Toolbar>
Share:
10,368
JeffreyM
Author by

JeffreyM

Updated on July 08, 2022

Comments

  • JeffreyM
    JeffreyM almost 2 years

    I'm using a Toolbar from "android.support.v7.widget.Toolbar".

    What is the best way to add (standard) icons into your android application?

    What i did...

    • I downloaded the icons from this website (24dp, white): https://design.google.com/icons/
    • Unzipped the zip files & put each icon into the specified folder in the app (hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi)
    • I added the mdpi icon to the folder (Resources/Drawable)

    Now I reference the the icon in layout like:

    android:icon="@drawable/ic_search_white_24dp"
    

    But my icons are a bit blurry. What am I doing wrong?

    Picture of the blury image (search icon)

    Toolbar

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    

    Searchview where I link to the icon

    <menu
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            tools:context=".MainActivity">
      <item
          android:id="@+id/action_search"
          android:orderInCategory="200"
          android:title="Zoeken"
          android:icon="@drawable/ic_search_white_24dp"
          app:showAsAction="ifRoom|collapseActionView"
          app:actionViewClass="android.support.v7.widget.SearchView"
          android:inputType="textCapCharacters"/>
    </menu>
    
  • JeffreyM
    JeffreyM almost 8 years
    And wich file from the folders (hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi) should I add to the drawable folder?
  • Sreeraj
    Sreeraj almost 8 years
    You should add all the files. You should be having all the drawable forlders in you Resources folder. If not you need to create them all. And add all the files to respective folders
  • Sreeraj
    Sreeraj almost 8 years
    Don't you have all drawable folders in Resources as shown in this image ? imgur.com/dzPS3pz
  • JeffreyM
    JeffreyM almost 8 years
    I added all the files but I need the icon in the drawable or it isn't working... I got these folders in my app: drawable - mpimap-hdpi - mpimap-mdpi - ... but only one drawable folder.
  • Sreeraj
    Sreeraj almost 8 years
    Expand all the folders under your Resources Folder ,showing all the files and share a screenshot so that I can have a look
  • JeffreyM
    JeffreyM almost 8 years
    Thank you! I added the drawable-folders (hdpi, mdpi, ...) and now I don't have the blurry icons!