Icons brooken and see like they are grayed out - android

I have a strange bug.
I have image as vector asset. It is created correct and see like:
I'm using it like menu icon on drawer:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/about"
android:icon="#drawable/ic_about_us"
android:title="#string/navigation_about" />
</group>
</menu>
But in device it looked broken:
Do you see images on the background? It's vector assets too, but they works fine. I place it from code.
I have the similar problem with ViewPager icons. It seems like only icons are broken. So i have two vector assets:
I set this icons two different way(specially):
layout_tab.getTabAt(0)?.icon = activity?.getDrawable(R.drawable.ic_type_bird)
layout_tab.getTabAt(1)?.setIcon(R.drawable.ic_hints)
And then i see:
One:
Two:
What is going on, why my assets broken?

Your assets are not broken, it is just that the navigation drawer automatically applies a color filter to the icons which makes them appear gray. It is similar for the tabbar (as it is trying to show the state)
The answer here shows how to stop this

Related

Android Navigation drawer custom icons

I've currently been looking into the navigation drawer of android and see the example code from android they use.
When starting a new project and selecting the navigation drawer activity. It gives basic structure which is great.
From this I see the icons used in the navigation drawer are android default. I wanted to see if possible to add my own png for icons. So far my code (in activity_main_drawer) is
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_connect"
android:icon="#drawable/icon_menu_connect_24"
android:title="Connect" />
<item
android:id="#+id/nav_settings"
android:icon="#drawable/icon_menu_settings_24"
android:title="Settings" />
<item
android:id="#+id/nav_help"
android:icon="#drawable/icon_menu_help_24"
android:title="Help" />
</group>
the _24 at the end of the name is just the 24pixel size indication.
Now after running this code all i get appear in my navigation drawer is square blocks and not the image.
Reason for using own png rather than android default, is looking at the defaults there was no images indicating what i wanted.
Appollogies if question has been posted before and thanks in advance
I have found the issue. I found that the image used in the menus need to have a transparent background. The images I was using did not get saved in that format and thus showed as a grey block. So although it gave a preview in the left hand margin in the XML file, it still was not in the right format
Using image asset to generate the icons was more efficient than lots of .PNG files

Customize Android Menu Navigation Drawer

i am using the Support Library Navigation Drawer and I want to customize it.
My Current Menu looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/activatedBackgroundIndicator">
<group
android:id="#+id/DrawerMainGroup"
android:checkableBehavior="single"
android:background="?android:attr/activatedBackgroundIndicator"
>
<item
android:id="#+id/drawer_home"
android:checked="true"
android:icon="#drawable/ic_home"
android:title="#string/home"
/>...
I want to have another icon on this. Do you think it is possible?
I searched the Web and could not fin anything useful for me.
Both images will be dynamically loaded. For example:
I have a app where i can get videos,pictures etc. That is the first Icon. Next to this, there should be a icon if this site is on homescreen or not.
Like: (IconType)(IconOnHome) Text
I don't know if this is even possible. I found app:actionlayout already, but i am not sure if I could load different images in to the xml.

Android: use built-in icons or download icon pack

I wonder if I should use the built in version of Google's icons for menu items or if I should download the icon pack instead?
Here's the default XML for my menu. It's using the built-in icons but the visual results looks a bit odd.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ParkItemActivity">
<item android:id="#+id/action_remove"
android:title="#string/action_remove"
app:showAsAction="ifRoom"
android:icon="#android:drawable/ic_menu_delete" />
<item android:id="#+id/action_save"
android:title="#string/action_save"
app:showAsAction="always"
android:icon="#android:drawable/ic_menu_save" />
</menu>
But if I use the icons from the Material-Design-IconPack, then it looks like this. But is there a recommended way? Remark: Can't find the trash-icon in the new icon-pack. And the delete/remove is a simple minus symbol.
android:icon="#mipmap/ic_remove_white_48dp"
android:icon="#mipmap/ic_save_white_48dp"
Yes you are right, default drawable icons present in the android sdk doesn't scaled up according to the material design. Android sdk by default is not supported with material icons, instead of that you could make use of appcompat-v7 support library, which has few materials icon by default like copy, paste, clear, search, back, menu icons respectively.
To use appcompat-v7 icons in your xml
#drawable/abc_ic_menu_paste_mtrl_am_alpha
Note: Only few icons are listed out in appcompat-v7. You don't have any other options without using Material-Design-IconPackonce if you want to use specific other icons.
I reccomend you to find icons you would like to use and if you use Eclipse, you can navigate: Right-click your project -> New -> Other -> Android Icon Set. Don't forget to check "Action Bar Tab Icons" and you will be able to generate icons correctly scaled for actionbar.

Android Menu Bar

I have created a sample android application that just displays some text and i can see that the menu bar at the top of the activity contains name of the application but not the icon of the application. The menu is also very thin just containing application name with a small font. Going through various tutorial i found that we have to select a particular menu style while creating the application to have a menu that contains both application name and icon, but my application just contains application name and the menu is very thin. Is it possible to increase the menu height now and add application icon to it dynamically or by making some changes in menu xml file?
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/app_name" android:icon="#drawable/ic_launcher"
android:title="My App" />
</menu>
If you want to customize the ActionBar, here you are a complete tutorial for it:
How can I implement custom Action Bar with custom buttons in Android?
It's very good an complete for customizing almost everything, so I recommend it to you.
Even tough, I ask you to change your question in order to make more clear the target of it, now you know what you were triying to mean ;)
<menu xmlns:tools="schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="com.example.sample.getMsgActivity"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<!-- Search, should appear as action button -->
<item android:id="#+id/action_write"
android:icon="#drawable/ic_action_refresh"
android:title="#string/action_write"
yourapp:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_read"
android:title="#string/action_read"
yourapp:showAsAction="never" />
REMEMBER: clean, then build. it should work then.

Text or Icon in action bar, stuck with the 3 dots

I'm making an android app in Eclipse. I want to place a text or icon in the action bar, but when I am writing in menu.xml, which looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/createnew"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:title="CREATE"/>
</menu>
it puts it in the options menu. I want to separate it.
I see this in the app when I run it:
(sorry can't post pictures because I don't have enough rep)
I want to CREATE next to the option menu like this for example:
Since you are using the AppCompat Actionbar, you need to use a custom namespaced showAsAction attribute.
It should look something like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/createnew"
android:orderInCategory="1"
yourapp:showAsAction="ifRoom"
android:title="CREATE"/>
</menu>
Note that this uses yourapp:showAsAction instead of android:showAsAction. This is because the showAsAction attribute is not available on pre-Honeycomb devices and is provided by the support library.
For more information, read the Action Bar developer guide.
It's caused by this line
android:showAsAction="ifRoom"
That tells Android to put it up there if it's going to fit nicely. If you want it up there no matter the fit use
android:showAsAction="always"

Categories

Resources