标签:
Button bt1 = (Button) findViewById(R.id.button_1); bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "您点击了按钮1", Toast.LENGTH_SHORT).show(); } });
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/add_item" android:title="Add"/> <item android:id="@+id/remove_item" android:title="Remove" /> </menu>
public boolean onCreateOptionsMenu(Menu menu){ super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.main,menu); return true; }
public boolean onOptionsItemSelected(MenuItem item){ switch(item.getItemId()){ case R.id.add_item: Toast.makeText(this, "您点击了Add按钮", Toast.LENGTH_SHORT).show(); break; case R.id.remove_item: Toast.makeText(this, "您点击了Remove按钮", Toast.LENGTH_SHORT).show(); break; default: } return true; }
public class SecondActivity extends AppCompatActivity{ protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </LinearLayout>
<activity android:name=".SecondActivity"> </activity>
Button bt1 = (Button) findViewById(R.id.button_1); bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this,SecondActivity.class); startActivity(intent); } });
<activity android:name=".SecondActivity"> <intent-filter> <action android:name="bistu.com.test.ACTION_START"/> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
Button bt1 = (Button) findViewById(R.id.button_1); bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent("bistu.com.test.ACTION_START"); startActivity(intent); } });
bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.baidu.com")); startActivity(intent); } });
<activity android:name=".SecondActivity"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http"/> </intent-filter> </activity>
bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:10086")); startActivity(intent); } });
Android学习第二天:Toast(提醒)、Menu(菜单)、Intent的显式和隐式(包括打开、适配网站,调用拨号界面等)
标签:
原文地址:http://blog.csdn.net/syker_guo/article/details/51901356