Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to add android standard icons in Xamarin

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>
like image 624
JeffreyM Avatar asked Apr 27 '16 06:04

JeffreyM


People also ask

How do I put icons on my xamarin app?

An easy way to change the icon is to replace the icon. png : design a set of icons in different sizes, and put each icon into the corresponding folder, make sure each icon is named icon. png , then the old icon file will be replaced. The launcher-foreground.

How to set app icon in Xamarin forms android?

open these folders, copy the image to your Xamarin android folder like following screenshot(For example, I copy the image from mipmap-hdpi folder, then I put it in your mipmap-hdpi folder of xamarin. android project, mipmap-mdpi , mipmap-xhdpi , mipmap-xxhdpi , mipmap-xxxhdpi are executed same operation).

How do I add an icon to a label in xamarin?

Regarding your requirement to add custom icon to the label can be achieved by following ways. Any custom icons can be added to the leading edge or the trailing edge of input view in the text input layout control. The events and commands related to the custom icons should be handled at the application level.


1 Answers

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>
like image 73
Sreeraj Avatar answered Oct 21 '22 09:10

Sreeraj