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>
Author by
JeffreyM
Updated on July 08, 2022Comments
-
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?
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 almost 8 yearsAnd wich file from the folders (hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi) should I add to the drawable folder?
-
Sreeraj almost 8 yearsYou 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 almost 8 yearsDon't you have all drawable folders in Resources as shown in this image ? imgur.com/dzPS3pz
-
JeffreyM almost 8 yearsI 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 almost 8 yearsExpand all the folders under your Resources Folder ,showing all the files and share a screenshot so that I can have a look
-
JeffreyM almost 8 yearsThank you! I added the drawable-folders (hdpi, mdpi, ...) and now I don't have the blurry icons!