Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First assign an id to the main xml linearlayout, for example in the following case it is named" container"</p> <pre><code> &lt;!-- main.xml --&gt; &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/container"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Then in the .java code you can find the layout object and set a drawable as its background:</p> <pre><code>package org.example.app; import android.app.Activity; import android.content.Intent; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.os.Bundle; import android.view.View; public class Main extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String pathName = "/sdcard/gif001.gif"; Resources res = getResources(); Bitmap bitmap = BitmapFactory.decodeFile(pathName); BitmapDrawable bd = new BitmapDrawable(res, bitmap); View view = findViewById(R.id.container); view.setBackgroundDrawable(bd); } } </code></pre> <p>Regards</p> <p>Ziteng Chen</p>
 

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