Android to achieve Toast prompt block diagram text coexisting method

  • 2021-01-25 07:55:14
  • OfStack

In this paper, an example of Android to achieve Toast prompt block diagram text coexist method. To share with you for your reference, as follows:

The procedure is as follows:


import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.util.Linkify;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class A05Activity extends Activity {
 private Button b;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    b=(Button)findViewById(R.id.button);
    b.setText(" According to Toast");
    b.setBackgroundColor(Color.GREEN);
    b.setOnClickListener(new OnClickListener(){
  @Override
  public void onClick(View v) {
  // TODO Auto-generated method stub
  ImageView iv=new ImageView(A05Activity.this);
     iv.setImageResource(R.drawable.icon);
     TextView tv=new TextView(A05Activity.this);
     tv.setText(R.string.title);
     LinearLayout ll=new LinearLayout(A05Activity.this);
     // judge TextView In what format is the content in and connected to the system 
     Linkify.addLinks(tv, Linkify.PHONE_NUMBERS|Linkify.EMAIL_ADDRESSES|Linkify.WEB_URLS);
  Toast t=Toast.makeText(A05Activity.this, tv.getText(), Toast.LENGTH_LONG);
  View v1=t.getView();
  ll.setOrientation(LinearLayout.VERTICAL);
  ll.addView(iv);
  ll.addView(v1);
  t.setView(ll);
  // Set up the Toast The relative position of the object in the phone 
  t.setGravity(Gravity.CENTER, 50, 50);
  t.show();
  }
    });
  }
}

Note: Because Toast belongs to Context in Activiyt, connections in Toast are not clickable. For example, in Toast, you can't double-click on Toast to open the URL.

More about Android related content interested readers can see the site features: Android control usage summary and Android development introductory and advanced tutorial

Hope this article described to everyone Android program design is helpful.


Related articles: