Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the volume of news is very low you could use Notifications as sugested, but as I assume an RSS feed may have a lot of things to notificate, it would flood the notification list if you want to display them one by one.</p> <p>Although Toasts can't be clicked, you could create an activity with a special theme and emulate the Toast behavior.</p> <hr> <h2>Detailed instructions</h2> <p>Ok, here we go! =)</p> <p>To make things clear i ended up writing a full example of an application acting as a Toast.</p> <p>The first thing we need is a class to act as our Toast. This class will do nothing but show itself and finish after a given time. You can handle other events to fit your needs as well, but this is the minimum necessary to reproduce the Toast behavior.</p> <pre><code>package com.rchiossi.popup; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.widget.TextView; public class MyPopup extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_popup); String message = getIntent().getStringExtra("message"); TextView messageView = (TextView) findViewById(R.id.message); messageView.setText(message); Handler handler = new Handler(); long delay = 1000; handler.postDelayed(new Runnable() { @Override public void run() { MyPopup.this.finish(); } }, delay); } } </code></pre> <p>As you can see, this class gets a String that has been passed as an Extra to the intent that started the activity, sets the text to be displayed and set a timer of 1000ms for the finish() method to be called. The display time can be adjusted to better fit user experience.</p> <p>The layout for this activity is very simple :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TextView android:id="@+id/message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@android:drawable/toast_frame"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>This layout is nothing but an empty screen with a text on the center. The trick here is to set the TextView background as "@android:drawable/toast_frame" which is the default background for Toasts.</p> <p>And now, to give it the final touch, you need to set the theme in AndroidManifest.xml to set the application background as transparent and remove the title. </p> <pre><code>&lt;activity android:name=".MyPopup" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar"&gt; &lt;/activity&gt; </code></pre> <p>The trick in here is the android:theme property. Theme.Translucent.NoTitleBar will give us an Activity with transparent background and no Title bar. So, when the activity is displayed, just the text and the Toast background will be visible.</p> <p>Good, now you have a working fake toast locked and loaded. But how to use it?! First, we create a dummy application to be our popup launcher. You won't need this in your project, as your own class will be launching the Toast. </p> <pre><code>package com.rchiossi.popup; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class Main extends Activity { /** Called when the activity is first created. */ private int mCount = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(Main.this,MyPopup.class); intent.putExtra("message", "My popup number " + mCount); mCount++; startActivity(intent); } }); } } </code></pre> <p>This application is basically just a button that when pressed shows you a Toast with a message. As you can see, to tell your Toast application what message to display, we use the <code>Intent.putExtra(name,message)</code> method. This data is rescued when MyPopup starts using the <code>Intent.getStringExtra(name)</code> method.</p> <p>You can get the source code of my example from here : <a href="http://www.mediafire.com/file/7vmuy8244vwh4dk/PopItUp.zip" rel="nofollow">http://www.mediafire.com/file/7vmuy8244vwh4dk/PopItUp.zip</a></p> <p>I hope it will help you out. =)</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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