I was trying to set the TabBar Icons dynamically by first downloading them from the server and then setting them as:
String path = context.getFilesDir().getAbsolutePath() + "/HDPI/" +"dial.png";
File imgFile = new File(path);
Drawable icon = Drawable.createFromPath(imgFile.getAbsolutePath());
dialer.setIndicator(getString(R.string.Keypad), icon).setContent(dialerIntent);
The Output that i get doing so is as followed :
I get the correct image but the size of the image gets reduced.
I don't understand why its so. I would be grateful if anyone can figure out the mistake that I make or could suggest me some new approach to do so.
Thanks.
Related
Trying to change the profile image on the web view.
But when trying the updated image showing a crashed image.
webView.loadUrl("javascript: (function() {document.getElementById('SelectedImage').src='"+profilePath+"';}) ();");
If profilePath is a Uri object, then you need to get the absolute path from the object. Use File f = new File(profilePath.toString());
I'm trying to use android's VectorDrawable as Image source in NativeScript. Using layout inspector I can see that there is something but no image is displayed. Also there is no error about missing image file, no errors at all.
I couldn't find out whether it's possible or not.
Thanks a lot in advance.
So I somehow figured it out:
let context = application.android.context;
// vector is VectorDrawable name
let logo = context.getResources()
.getIdentifier(this.vector, "drawable", context.getPackageName());
this.el.nativeElement.android.setBackgroundResource(logo);
// Access CSS color to change fill color
let backgroundColor: string = (this.el.nativeElement.backgroundColor)
? this.el.nativeElement.backgroundColor.toString()
: SrcDirective.DEFAULT_COLOR;
let newBackgroundColor: Color = new Color(backgroundColor);
this.el.nativeElement.android.getBackground().setTint(newBackgroundColor.android);
Ok, after searching and browsing over the internet, I just didn't get what I was looking for. I have a database with a field for "Path", where my images file names are listed.
**Table1:**
PATH ID
imgRice.jpg 1
imgMango.jpg 2
imgBanana.jpg 3
Now I want my imageView to change picture accordingly from my query:
"Select Path from table1 where ID = 1";
I will declare a String, like String queryResultString to handle the result (ex.imgRice.jpg).
I want a code that looks like imgView.image="drawable/" + queryResultString
Any help is appreciated. Thanks guys!
Thanks for the comments and suggestions guys, highly appreciated.
But I've got a simple yet tricky turnaround for my problem.
First, it is IMPOSSIBLE to rip the Drawable path because it is compressed when published to .apk file.
Second, to make it possible, you need to use id for every file in your drawable.
Third, it is much better to add files(images) to asset folder(\app\src\main\assets).
Lastly, follow these simple codes:
//code to initiate the object ImageView...
ImageView myImage = (ImageView) findViewById(R.id.pic);//pic is the id of ImageView in my xml file...
try
{
// now, get the input stream
InputStream input= getAssets().open(c.getString(c.getColumnIndex("image")));//image is the name of field in my db which holds the path (ex. rice.jpg)...
// initiate image as drawable
Drawable draw = Drawable.createFromStream(input, null);
// set image to ImageView
myImage.setImageDrawable(draw);
}
catch(IOException ex)
{
return;
}
Enjoy Coding! ^_^
i developing an application, in that i configure html data . But the background image for data is not effected means the image path is not getting.
i placed my image :res/drawable-hdpi folder.
and i am using the following logic:
strBody += "<tr><td background='../res/drawable-hdpi/msgblue_box.png' style='word-break:break-all;width:50%;'>" + dslist.get(i).getBody()+"<br>"+ dslist.get(i).getDateformat()+ "</td><td style='width:50%'></td></tr>";
So, please guide me how solve this.
you need to use the getResources.getDrawable to get image in your code
ImageView img=new ImageView(this);
Drawable im= getResources().getDrawable(R.drawable.name);
img.setImageDrawable(im);
strBody += "<tr><td background="+img+ "style='word-break:break-all;width:50%;'>" + dslist.get(i).getBody()+"<br>"+ dslist.get(i).getDateformat()+ "</td><td style='width:50%'></td></tr>";
I am very new to Android development.
I am trying to add an image to my Android application by code. I found this, but it is showing some drag and drop way to do it.
I want to do it by coding in my onCreate method.
I managed to do this:
ImageView iv = new ImageView(this);
But could not figure out how to set the image-uri.
I tried the following:
iv.setImageURI(#"C:\Users\SONY\Downloads\slide.butcher.home.jpg");
with and without # but I think I need to pass an URI.
I tried to create an object of android.net.Uri, but it seems it can not be instantiated.
See the uri you have tried is wrong it is located on your local file system.. Instead try to push the image on the device's sdcard with the help of DDMS of eclipse..
Suppose you have pushed it on /sdcard/your_image.jpg. then in your code set your image path as
imageView.setImageUri (Uri.parse("/sdcard/your_image.jpg"));
I m sure you will get it...
ImageView iv = (ImageView)findViewById(v);
iv.setImageResource(R.drawable.image);
iv.setImageURI(#"C:\Users\SONY\Downloads\slide.butcher.home.jpg");
You are trying pass Uri of image which is stored on your Computer!!!!
Copy that file on your device SD Card.
Suppose you copied it under /sdcard/home.jpg
Then use below code to display it in ImageView.
imageView.setImageUri(Uri.parse("/sdcard/home.jpg"));