There are several custom-made graphic objects (.png files) included in the project inside res/drawable map.
All elements are normally loaded and displayed in the user interface except two icons and so far haven't figured out what causes the problem.
The code which doesn't affect the user interface as it should is the following:
if (settings.isMute()) {
muteIcon.setIconImage(R.drawable.ic_volume_off_small);
} else {
muteIcon.setIconImage(R.drawable.ic_volume_small);
}
In both cases there is only ic_volume_small displayed on the screen and the Variables window in the IDE displays the following:
R.drawable.ic_volume_small = Class not
loaded : net.client.android.R$drawable
R.drawable.ic_volume_of_small = Class
not loaded :
net.client.android.R$drawable
The method (member of IconImage class) which should change the icon image is the following:
public void setIconImage(int imageFromResources) {
iconImage = BitmapFactory.decodeResource(getResources(), imageFromResources);
iconWidth = iconImage.getWidth();
iconHeight = iconImage.getHeight();
invalidate();
}
Does anyone know what could cause the described problem?
Thanks!
Assuming what you want is the drawable from the Android framework and not your own, you'd want to use:
android.R.drawable.ic_volumne_off_small
rather than
R.drawable.ic_volume_off_small
(notice the android prefix).
If you recently added file, please refresh (press F5) the drawable directory and R is going to be generated again. Once R is regenerated, you can use the newly added resource.
Related
I am trying to change the texture of my object with this code:
Texture2D baileyburlwood = Instantiate(Resources.Load("bailey burlwood") as Texture2D);
myObject.GetComponent<Renderer>().material.mainTexture = baileyburlwood;
It is working perfectly fine in the editor, the texture changes but when I tried to run it in my android device, my object just goes black. There is also no error or any warning. Pls help! Thanks!
I am using Unity 5.5.1f btw
From the screenshot in your updated question, the image you want to load is called bailey burlwood.jpg which is already in the Resources folder..
Herein lies the problem:
Instantiate(Resources.Load("bailey burlwood") as Texture2D);
You instantiate prefabs, scripts and components not normal classes like Texture2D.
Your code would have worked if bailey burlwood.jpg is bailey burlwood.prefab and you load it with GameObject prefab = Resources.Load("shipPrefab", typeof(GameObject)) as GameObject; but that's not the case here.
Since the "bailey burlwood" file is a JPG file, you should load like this:
Texture2D baileyburlwood = Resources.Load("bailey burlwood") as Texture2D;
myObject.GetComponent<Renderer>().material.mainTexture = baileyburlwood;
Note that there is no Instantiate function involved. See this post for how to load other image files with different image settings when using the Resources folder.
I am using UMP example provided by Google, I have not made any change in my code, even I have not tried anything out of the box, I just imported your project into my work-space and checked it on my device, and found that I am not getting Thumb with Genres (Songs by genre) and List of Genres...
Whereas I supposed to get Thumb from our JSON, here is what I have tried (but no success) -
holder.mImageView.setImageBitmap(description.getIconBitmap());
UPDATE # 1 AS PER SUGGESTED BY #NageshSusarla here
holder.mTitleView.setText(description.getTitle());
holder.mDescriptionView.setText(description.getSubtitle());
AlbumArtCache cache = AlbumArtCache.getInstance();
Bitmap art = cache.getIconImage(url);
if (art == null) {
cache.fetch(url, new AlbumArtCache.FetchListener() {
#Override
public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) {
if (artUrl.equals(url)) {
holder.mImageView.setImageBitmap(icon);
}
}
});
} else {
holder.mImageView.setImageBitmap(bitmap);
}
holder.mImageView.setImageBitmap(description.getIconBitmap());
and getting Cannot resolve symbol 'url'
The icon bitmap may not have been set. It's best to use the AlbumartCache to fetch the icon and then set it on the imageView. The url to be passed to AlbumArtCache.getInstance().fetch(url,..) is description.getIconUri().toString()
The reason you may not be seeing it in uAmp is because of the tint being applied to it. You can remove the tint from media_list_item.xml to try out the changes.
Aside: This is indeed by design and the icon is only shown at the bottom when a user selects the item to be played.
This is by design. To keep the navigation cleaner, we decided to not
show the MediaItem icon on the local browsing UI. Other browsing UI's
may show it, like Android Auto and Android Wear.
I think you should check it in issues of android-UniversalMusicPlayer. Take a look at comment given by mangini here.
If you want to change uAmp to show the MediaDescription.getIconUri,
set the holder.mImageView at this.
Hi I am beginner in android and I am trying to learn it, I wrote a small code for changing the background image of the application when clicking on some button:
public void processClicks(View display)
{
display.setBackgroundResource(#drawable/fgd4);
}
but it got me an error message that :
drawable cannot be resolved to a variable
fgd4 cannot be resolved to a variable
but I have created a folder named drawable in the res folder and I put the fgd4.jpg image in it.
Please help me to solve this small problem
You must reference your drawable in code differently than you do in your XML layouts.
display.setBackgroundResource( R.drawable.fgd4 );
Try Like This:
display.setBackgroundResource(R.drawable.fgd4);
i succeed in using this code in a new project, but, when copying it in my actual code, the image displayed is not the good one
everything is well made (image is in the folder drawable, every data well declared, ...)
image begin with "phoXX", where XX is an integer (between 0 and 62)
i have an imageview (named imageView1) and a TextView (to debug, named textView1) in which i display the ID (which one is good when checking in R.java...)
here is my code :
private Context mContext;
ImageView imageC=(ImageView)findViewById(R.id.imageView1);
TextView Tex=(TextView)findViewById(R.id.textView1);
Drawable drawableX = this.getResources().getDrawable(android.R.drawable.ic_dialog_alert);
Random random_monster = new Random();
int lerand = random_monster.nextInt(62);
int id = mContext.getResources().getIdentifier("drawable/pho"+lerand, "drawable",mContext.getPackageName());
if (id>0)
{
drawableX = getResources().getDrawable(id);
}
imageC.setImageDrawable(drawableX);
Tex.setText(Integer.toString(lerand)+":"+id);
So, as i say, an image is displayed, a number is displayed, but pho29 for exemple show the image named pho48 (and pho48 doesn't display pho29 if you ask)
ID is 2130837535, which is what appears in R.java :
public static final int pho29=0x7f02001f;
pho48 is :
public static final int pho48=0x7f020034;
for some number, the image displayed is the good one, for other, the image is not the good one (and it's always the same image displayed for the same number....i mean for pho29, it's ALWAYS pho48 which is displayed, in every one of my activity)
I really don't understand what i miss...Thx all for any kind of help
Edit : below some matching (on the left side the number which should be displayed, on the right the number displayed)
2->6
17->32
19->34
24->41
43->43
51->51
36->55
37->56
38->57
56->56
59->59
61->61
As you can see, 56 is displayed by 56 AND 37....
If the same code and set of image resources work fine in one project and not in another, you should consider whether the compiled resources in the broken project are actually correct. I have found when using the automatic build feature in Eclipse that the resources don't get recompiled when I expect them to. For instance if the last thing I did before deploying an app was to change the resources. Saving a code file change seems to drive the build system harder.
You should try doing a clean then a rebuild. In Eclipse, on the Project menu choose "Clean..." and pick your project (or let it clean them all). Eclipse will then do a full rebuild. Or on the command line run "ant clean" followed by "ant debug".
Also you are using this line:
int id = mContext.getResources().getIdentifier("drawable/pho"+lerand, "drawable",mContext.getPackageName());
Here is the API spec:
public int getIdentifier (String name, String defType, String defPackage)
You don't need to specify the type in the name field, because you are specifying it in the defType field. I don't think it will solve your problem, but this should work at least as well:
int id = mContext.getResources().getIdentifier("pho"+lerand, "drawable",mContext.getPackageName());
Try to put the imageview without source in its definition, sometimes I have the problem when an imageview has source set in xml, changing its drawable in runtime not work, the first image is always visible
I am writing an Android app and have run into a very strange situation. I have an animation-list xml file that I have created for an animated loading graphic named 'loading.xml' and I am setting it as the background for an ImageView in my code. It is something like this:
public void startLoading() {
if(!isLoading) {
loading.setBackgroundResource(R.drawable.loading);
loading.post(new Runnable() {
public void run() {
anim = (AnimationDrawable) loading.getBackground();
anim.start();
}
});
flMask.setBackgroundResource(R.drawable.mask_loading);
flMask.setVisibility(View.VISIBLE);
flMask.bringToFront();
isLoading = true;
}
}
This works wonderfully with no problems whatsoever. However, if I rename 'loading.xml' to 'anim_loading.xml' (to keep it inline with my usual naming scheme) I get a force close with
java.lang.ClassCastException: android.graphics.drawable.ColorDrawable
at the line where
anim = (AnimationDrawable)loading.getBackground();
After changing the name, it force closes, and if I change it back to just 'loading.xml' it works fine again.
I am really stumped on this one. I have tried creating a completely new file with the correct name, various clean/builds, closing/reopening Eclipse, closing/reopening the AVD, wiping the AVD and reinstalling fresh, I have tried renaming the xml file to something else entirely, and there are no other resources with the same names. So far, nothing has worked outside of leaving the file named 'loading.xml', which at least it works, but it is annoying. I haven't been able to find anyone with the same type of problem, which as vast as SO and the internet are, usually means that it's something stupid that I have missed somewhere along the line.
Does anyone have any ideas on why it will not let change the name on this file?
After giving up and just leaving it alone for a little while, I just stumbled upon the answer to this question!
Apparently, there is some sort of bug with Android that causes the first file in the res/drawable directory to be viewed as a ColorDrawable regardless of what it actually is. Before, when I was trying to change the name of the file, the new name put it at the top of the list in the directory and that was enabling this bug to show itself. Without the name change, the top item in my drawable directory just happened to be a ColorDrawable so I never noticed this weird bug until after I tried changing that name.
To solve the problem (or rather, to work around the problem) I created an empty dummy file in the res/drawable directory named a.xml. As odd as it may sound, it fixed everything!
You should save in drawable res/drawable/rocket.xml
It will fix the question.