//官方帮助文档:http://wear.techbrood.com/guide/topics/ui/notifiers/toasts.html
<LinearLayout xmlns:andro
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <Button android:
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="show short"/>
    
	<Button android:
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:text="show long"/>
	
	<Button android:
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:text="show diy"/>
	
	<Button android:
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:text="show image"/>
</LinearLayout>


	private Button btnShowShort;
	private Button btnShowLong;
	private Button btnShowDiy;
	private Button btnShowImage;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        btnShowShort=(Button) findViewById(R.id.btnShowShort);
        btnShowShort.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(MainActivity.this, "show short",Toast.LENGTH_SHORT).show();
			}
		});
        
        btnShowLong=(Button) findViewById(R.id.btnShowLong);
        btnShowLong.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(MainActivity.this, "show long",Toast.LENGTH_LONG).show();
			}
		});
        
        btnShowDiy=(Button) findViewById(R.id.btnShowDiy);
        btnShowDiy.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast toast=Toast.makeText(MainActivity.this, "show diy",Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 100, 100);
				toast.show();
			}
		});
        
        btnShowImage=(Button) findViewById(R.id.btnShowImage);
        btnShowImage.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast toast=Toast.makeText(MainActivity.this, "show long",Toast.LENGTH_LONG);
				ImageView image=new ImageView(MainActivity.this);
				image.setImageResource(R.drawable.cool);
				toast.setView(image);
				toast.show();
			}
		});
    }

效果:

Android 弹出通知Toast的使用

Android 弹出通知Toast的使用

Android 弹出通知Toast的使用

Android 弹出通知Toast的使用

相关文章:

  • 2022-12-23
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-25
  • 2021-12-04
  • 2021-05-21
  • 2022-01-03
  • 2022-01-22
相关资源
相似解决方案