Note that there are some explanatory texts on larger screens.

plurals
  1. POchange background image of Framelayout via URL
    primarykey
    data
    text
    <p>is it possible to use a <code>url</code> to set <code>background</code> for <code>framelayout</code>?</p> <p>Example: i want to use the URL like <a href="http://www.mydomain.com/images/filename.jpg" rel="nofollow">this</a> as my <code>framelayout</code> background.</p> <p>what i really want to achieve is that when my activity loads it will fetch the image from my domain and use it as my framelayout background image. i was able to do this but i used a imageview and a button.</p> <p><strong>below is the code that i use:</strong></p> <pre><code>public class MyAppActivity extends Activity { ImageView imView; String imageUrl= "http://www.mydomain.com/resource/images/"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button bt3= (Button)findViewById(R.id.postbutton); bt3.setOnClickListener(getImgListener); } View.OnClickListener getImgListener = new View.OnClickListener() { public void onClick(View view) { downloadFile(imageUrl+"image"+".png"); Log.i("im url",imageUrl+"image"+".png"); } }; Bitmap bmImg; void downloadFile(String fileUrl){ URL myFileUrl =null; try { myFileUrl= new URL(fileUrl); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bmImg = BitmapFactory.decodeStream(is); imView.setImageBitmap(bmImg); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre> <p><strong>and here is my XML codes:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/rakistaradiobg" android:orientation="vertical" &gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="98dp" android:layout_gravity="bottom|center" android:scaleType="fitXY" android:src="@drawable/btnbg" /&gt; &lt;Button android:id="@+id/postbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:text="Button" /&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload