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...
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>
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.
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).
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With