安卓app_sl3.10游戏界面设计按钮点击事件-toast notification-点击进入弹出消息自动关闭
package com.example.sl3_10; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView img0=(ImageView)findViewById(R.id.imageButton0); img0.setOnClickListener(new OnClickListener() { @Override public void onClick(View v){ Toast.makeText(MainActivity.this, "进入游戏", Toast.LENGTH_SHORT).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.sl3_10.MainActivity" > <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="centerCrop" android:layout_weight="1" android:src="@drawable/top" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bottom" android:id="@+id/relativeLayout1" android:layout_weight="2" > <ImageView android:id="@+id/imageButton0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/in" /> <ImageView android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/imageButton0" android:layout_alignRight="@+id/imageButton0" android:src="@drawable/setting" /> <ImageView android:id="@+id/imageButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/imageButton0" android:layout_alignLeft="@+id/imageButton0" android:src="@drawable/exit" /> <ImageView android:id="@+id/imageButton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_alignTop="@+id/imageButton0" android:layout_toLeftOf="@+id/imageButton0" android:src="@drawable/help" /> <ImageView android:id="@+id/imageButton4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/imageButton0" android:layout_alignTop="@+id/imageButton0" android:src="@drawable/board" /> </RelativeLayout> </LinearLayout>