I have been able to change colour of an activity background (see this post). Now a requirement is to do the same with background image. I mean I can click a button, select an op
add this to your activity.xml:
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/iso"
android:id="@+id/background"
android:scaleType="fitXY"
/>
add this to activity.java:
ImageView layout = (ImageView) findViewById(R.id.background);
layout.setBackgroundResource(R.drawable.iso);
webView.setBackgroundColor(0);
WebView.setBackgroundResource(R.drawable.yourImage);
use this above code, may this help you....
When you are setting background after selecting from Dialog
then you are getting the resource id R.drawable.pix2
and retrieving the BitmapDrawable
as follows...
wvContent.setBackgroundColor(0);
BitmapDrawable bg = (BitmapDrawable)getResources().getDrawable(R.drawable.pix2);
bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
wvContent.setBackgroundDrawable(bg);
bg_color=R.drawable.pix2;
But in onCreate()
method you are just passing the resource id as below...
wvContent.setBackgroundColor(getSelectedItem());
where, getSelectedItem()
returns an int
value which is a resource id.
Now, set background drawable as follows in onCreate()
method...
wvContent.setBackgroundColor(0);
BitmapDrawable bg = (BitmapDrawable)getResources().getDrawable(getSelectedItem());
bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
wvContent.setBackgroundDrawable(bg);
You can update background from SDCard as follows...
String pathName = Environment.getExternalStorageDirectory().getPath() + "/folder/" + "image.jpg";
Resources res = getResources(pathName);
Bitmap bitmap = BitmapFactory.decodeFile(pathName);
BitmapDrawable backgroundDrawable = new BitmapDrawable(res, bitmap);
wvContent.setBackgroundDrawable(backgroundDrawable);