Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is how I did it.</p> <p>I made a layout file for the custom titlebar thing, that has an ImageView.</p> <pre><code>&lt;merge xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;ImageView android:id="@+id/title_statusimg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/connected" android:layout_centerVertical="true" android:layout_alignParentRight="true" /&gt; &lt;/RelativeLayout&gt; &lt;/merge&gt; </code></pre> <p>I include this in every activities layout file i want to use it.</p> <pre><code>&lt;include layout="@layout/titlebar" /&gt; </code></pre> <p>Also, i made a StatusActivity that extends Activity. It receives a Broadcast that is send from whenever an background thread detects a change in the connectivity to the webserver.</p> <pre><code>public class StatusActivity extends Activity { private String CONNECTION_STATUS = "app.CONNECTION_STATUS"; private ImageView conn; @Override protected void onResume() { super.onResume(); IntentFilter iFilter = new IntentFilter(CONNECTION_STATUS); registerReceiver(mBroadcastReceiver, iFilter); conn = (ImageView) findViewById(R.id.title_statusimg); if (ConnectionControl.isOnline()) { conn.setImageResource(R.drawable.connected); } else { conn.setImageResource(R.drawable.nconnected); } } @Override protected void onPause() { super.onPause(); unregisterReceiver(mBroadcastReceiver); } private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (ConnectionControl.isOnline()) { conn.setImageResource(R.drawable.connected); } else { conn.setImageResource(R.drawable.nconnected); } } }; </code></pre> <p>}</p> <p>Every Activity that shall use this Status-Image extends StatusActivity instead of Activity.</p> <p>Hope i covered everything, atleast for me it's working.</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