/* 需要在AndroidManifest文件中添加访问网络的权限
* <uses-permission android:name="android.permission.INTERNET">
* </uses-permission>
*/
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
openOptionsDialog();
}
private void openOptionsDialog(){ //打开一个对话框
new AlertDialog.Builder(this).setTitle("关于JET")
.setMessage("Android Jet") //设置对话框的文本信息
.setPositiveButton("确认", new DialogInterface.OnClickListener() { //添加一个按钮, 按下后无动作直接返回
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
})
.setNegativeButton("主页", new DialogInterface.OnClickListener() { //添加一个按钮, 按下后打开浏览器上uri指定页面
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Uri uri = Uri.parse("http://www.baidu.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri); //设置Intent的动作和数据
startActivity(intent);
}
})
.show();
}
}
android基础--AlertDialog对话框
最新推荐文章于 2024-06-17 02:23:19 发布