Add fontawesome icons in my toolbar items menu - android

I'm trying to add Font Awesome library to my android project but i just can't. I was reading each google result about this topic.
My menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/buzon"
android:icon="#drawable/ic_buzon"
android:title="#string/buzon" />
<item
android:id="#+id/objetivos"
android:icon="#drawable/ic_objetivos"
android:title="#string/objetivos" />
<item
android:id="#+id/home_action"
android:icon="#drawable/ic_go_home"
android:title="#string/title_home" />
<item
android:id="#+id/encuesta"
android:icon="#drawable/ic_encuesta"
android:title="#string/encuesta" />
<item
android:id="#+id/cursos"
android:icon="#drawable/ic_cursos"
android:title="#string/cursos" />
</menu>
I'm want to use Font Awesome icons in my items menu instead default android icons.
For references, i was trying to follow this guide without success.
How to use Font Awesome icon in android application?

Related

How to achieve a ripple animation by clicking on a menu item?

I have a toolbar
There is a overflow that displays options in menu
On click of menu item, How to achieve a ripple animation
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menuEventsTodayId"
android:title="#string/menu_events_today" />
<item android:id="#+id/menuUpcomingEventsId"
android:title="#string/menu_upcoming_events" />
<item android:id="#+id/menuSignOutId"
android:title="#string/menu_sign_out" />
</menu>
I tried with:
<item android:id="#+id/menuEventsTodayId"
android:background="?attr/actionBarItemBackground"
android:title="#string/menu_events_today" />
Its not working, How to properly achieve it
Just add the background as ?attr/selectableItemBackground. It will automatically give ripple on Android 5+
You can use following for android version above lollipop:
android:foreground="?attr/selectableItemBackground"
for prelollipop devices, you can use following:
compile 'com.balysv:material-ripple:1.0.2'
You need to define a separate style for your toolbar in the 'values' folder then add the following items to it:
<item name="selectableItemBackground">?android:selectableItemBackground</item>
<item name="android:colorControlHighlight">#color/ripple_material_dark</item>
Note:- As you can check this Link. ?android:selectableItemBackground is only properties which makes this animation.

i can't add the menu icons to the tool bar in visual studio xamarin

it seems that what ever i did i cant set the icons visible to the tool bar, i've tried to do researches on many platforms, but nothing helped.
here is the xml menu:
<?xml version="1.0" encoding="utf-8" ?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/event_ic"
android:icon="#mipmap/ic_event"
android:title="profile"
android:showAsAction="always"
/>
<item
android:id="#+id/details_menu"
android:title="details"
android:showAsAction="never"/>
</menu>
you can see that even if i set the android:showAsAction to always, i still get the event item in the pop up menu without the icon.

Why do I need to use app namespace in menu items when using AppCompat

Previously, before using AppCompat, I was using SherlockActionBar to support Android 2.3.
The following menu works just perfect under SherlockActionBar
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_browser"
android:title="#string/menu_browser"
android:showAsAction="ifRoom"
android:icon="?attr/actionBarBrowserIcon"/>
<item
android:id="#+id/menu_share"
android:title="#string/menu_share"
android:showAsAction="ifRoom"
android:icon="?attr/actionBarShareIcon"/>
</menu>
However, even since migrating to AppCompat, I realize the above menu doesn't work. I need to use app namespace, in order to make it work.
<?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/menu_browser"
android:title="#string/menu_browser"
app:showAsAction="ifRoom"
android:icon="?attr/actionBarBrowserIcon"/>
<item
android:id="#+id/menu_share"
android:title="#string/menu_share"
app:showAsAction="ifRoom"
android:icon="?attr/actionBarShareIcon"/>
</menu>
Why is this so? What is the difference comparing to SherlockActionBar, which makes app namespace unnecessary?
Attributes provided by libraries (or by the app itself) are suppose to be namespaced in order to avoid conflicts/collisions.
ActionBarSherlock masks this behavior by naming the attribute android:showAsAction. (As opposed to a showAsAction attribute in the android namespace): https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock/res/values/abs__attrs.xml

Trying to color tabs on ActionBar

I am adding an actionbar to a test app I'm writing, and I see questions throughout stackoverflow about this, but nothing that has helped me at all. Based off of this guide:
http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
I'm trying to change the select color for tabs that i'm using on my action bar. The default is that faint blue color. Just as a test I did this:
<style name="CustomTab" parent="android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#000000</item>
</style>
That gives me a solid black tab completely, not the selector part. Can someone help better direct me here? I can't seem to find a good example anywhere.
First you have to define a selector xml file then write this code there and replace your code with this
item name="android:background">#drawable/yourfilename</item>
and the selector xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="#drawable/picture_selected" />
<item
android:state_focused="true"
android:drawable="#drawable/picture_selected" />
<item
android:drawable="#drawable/picture_unselected" />
</selector>

Android Menu Icon with Title : Title doesn't display

Here is my XML
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/refresh" android:title="Home"
android:icon="#drawable/menu_home" />
<item android:id="#+id/search" android:title="Search"
android:icon="#drawable/menu_search" />
<item android:id="#+id/help" android:title="Help" android:icon="#drawable/menu_help" />
</menu>
Icon is getting displayed but title doesn't. Please advise.
I'll post this as an answer then...
The size of menu pixes can be too large (such as 72x72). Make sure you use the proper size icons for your current display.
I had the same problem, but my menu icon size was 32x32. And still displayed over the text. So, I played a little with the sizes, and set it to about 47x47 and it finally worked.
So, if this happens, try to play with the image sizes.

Categories

Resources