Xamarin Forms image not showing-Android - android

I have a Xamarin Forms Android app and when I'm using the following code
var image = new Image { Source = "lock.png" };
to show an image, but the image isn't showing though.
And then I try to change the source to Icon.png (the default Xamarin icon) and it working fine.
Does anybody know how to make this image show in my app?
(ps: image path : ".\MyApp.Droid\Resources\drawable\lock.png".)

Make sure that image has Build Action set to "Android Resource". Otherwise, it is not copied to final package properly and there is no image for app to show.
This is described in guide here: https://developer.xamarin.com/guides/xamarin-forms/working-with/images/#Local_Images

I also faced to this issue. I tried above mentioned two solutions too. But didn't.
People can try below suggestions one by one,
In Solution Explorer -> right click on image -> select "Include to project"
Go to image properties -> Build Action -> set to "Android Resource"
Check whether your image file name contains dashes or hyphens
Clean the project
Build the project and Run the project
I didn't build the project, after adding the image. It was my problem.
May someone get benefited from my answer.

For others who may come here, also check to make sure your image doesn't have dashes/hyphens in the file name as per https://stackoverflow.com/a/35760195/908677 - that was why my image wasn't showing up.

Another problem could be that the image is too large to be rendered. If everything else fails, try creating a smaller version of the image.
I hope this helps somebody.

Related

Is there any way out to solve this import' node:js' error of flutter?

I am new to flutter. Tried every possible to resolve this including importing the file to removing the file. nothing worked and Ienter image description here am pissed off.
click on the text in blue to see the CODE
dart:js is a web-only package. You simply can't use it for mobile apps. Hovering over the line in your code would have informed you about that

My Android studio Drawable Resource Folder Imports in a very crowded manner

I'm currently following a tutorial, Currently, it is required to import multiple images drawable folders for different densities by simply copying and pasting it to android studio
picture of the Folder from which we import the images
Image of the tutorial after pasting
and This is Me after pasting
as you can see me pasting, Creates a directory for each image with the corresponding density
which makes the drawable folder very crowded, so am I doing something wrong ? or this is new in android studio ? because I remember an old project of mine which didn't import it like that, Thank you for your time and be patient with me
There is actually no problem. It is the view that you are using which is different. If you want yours to look like the on in the tutorial, you should go right to the top of that window (that shows you) and look for the android "face" or sign with the word "Android" next to it and an arrow pointing downwards and click on that android sign. A dropdown menu will open up and then you should choose the "Project" option option. Now your files will look like the ones in the tutorials.
Check this website if you are confused :
https://developer.android.com/studio/projects
You might be using Project View , try changing it to Android View.
You can find it on the top-left corner.

R.drawable being replaced with android.R.drawable

I am following a video tutorial for Android Studio that tells me to enter this line:
public class customswipeadapter extends PagerAdapter {
private int[] image_resources = {R.drawable.picture};
}
Everything is good until I try to enter the R.drawable Android Studio only offers the suggestion android.R.drawable which is then flagged as an error.
How can I solve this?
This happens sometimes when your android studio has Imports on the fly :P. To configure your Android studio use this link. And also do this steps,
Go to settings->Editors->General->Auto Import
In JAVA uncheck Optimize import on fly, and Add unambiguous imports on fly.
You can use both R.drawable.picture and android.R.drawable. Android Studio support both. So if you want to use R.drawable.picture just simply type but remember in your drawable folder image name picture must be save.
In you project directory, there should be a file called 'res'. If you right click on that and select new Android Resource Directory, it'll take you to another window. From here, change resource type to show drawable, and click OK. Now, put whatever image you would like to draw into drawable, and you should be good to reference it in your code like you were trying to do.
I've had some issues with this in the past, and once or twice I just had to restart Android Studio. Rebuilding the project may also work, but I've had better luck with a simple restart.

Android Studio Adding image asset not working

I'm trying to add an image in Android studio by right clicking on the drawable folder->new->Image Asset, I add an Action Bar and Tab Bar icon with a custom image and I click finish and it looks like its doing something but nothing appears in the drawable folder. I'm also unable to reference the new image name in any xml. What's funny is if I go to re-add this image, it says the image already exists and it will be overwritten. Am I doing something wrong?
I create a new project with Android Studio and generate image asset in the new project. It begins to work. I don't know what's wrong with the previous project. Hope it also helps for you.
As #Varun said, Before click on Finish, check save path by click on "Next" button.
TLTR: fix any other icon type you touched before.
In my case it was because of wrong path to foreground image path (the source image was deleted):
So even after changing the icon type the error does not disappear (buttons are disabled):
So fix other icon types.
In Background Layer set Asset Type to "Color"

Android Studio Refactor > Extract > Style Disabled

I am trying to extract style in android studio 0.8.9 using the refactor option. But it seems to be disabled for some reason. I have tried cleaning and rebuilding the project just in case and even restarting Android Studio, but nothing seems to enable the extract style option.
Do let me know if anybody else is facing the same problem or is there a way to solve this ?
Screenshot image:
I had the same problem. Extracting styles is different in Android Studio:
You don't need to select text and choose Refactor->Extract->Style, just choose the menu option With no text selected.
So, just click anywhere inside the ImageView element (Do not select any text). The refactor option should become available.
Works fine for me without selecting any code. To extract layout you need to select the whole layout not just a part of it.

Categories

Resources