Write to /Res/Drawable/ on the Fly

Write to /res/drawable/ on the fly?

Everything in the apk will be read only.
And it's even better: android doesn't extract the apk when you install a program, so the size consumed is kept to minimal.

android image save to res/drawable folder

Its not possible.

The following link can be helpful

  • Write to /res/drawable/ on the fly?

Saving to drawable folder programmatically in Android

No, it's not possible. "The drawable folder" doesn't exist as a file system folder at runtime - it's part of your (read-only) binary .apk file.

android generate resource on the fly

I think you're looking for the StateListDrawable class. You can create these in code, add states to it (e.g. your downloaded pressed png file) and then set it to your button with button.setBackgroundDrawable(stateList).

Android studio can not detect the source file in res/drawable

Solution - first problem

The resource name must start with a letter (not number).

Solution - second problem

Use just:

@drawable/039_cloud

instead

@drawable/039_cloud/039_cloud

so:

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/039_cloud" />

Android Studio

Android Studio is grouping same images, but for different DPIs.

When you choose Android view, you will have:

enter image description here

But when you will choose Project you will see "real" project structure:

enter image description here

Adding Images to Drawable Folder from a Server

Quoting Android Engineer RomainGuy

You cannot write to res/drawable.

However you can look for other alternatives like external storage.

Links to consider are

android image save to res/drawable folder

How to convert a Drawable to a Bitmap?

Android: Image save to location

How to set the image from drawable dynamically in android?

Try this:

String uri = "@drawable/myresource";  // where myresource (without the extension) is the file

int imageResource = getResources().getIdentifier(uri, null, getPackageName());

imageview= (ImageView)findViewById(R.id.imageView);
Drawable res = getResources().getDrawable(imageResource);
imageView.setImageDrawable(res);


Related Topics



Leave a reply



Submit