标签:android style blog http ar color os sp java
只有脚踏实地的人,才能够说:路,就在我的脚下。
本讲内容:Dialog 对话框
例三:信息内容是一个简单的View类型
下面是MainActivity.java主界面文件:
public class MainActivity extends Activity{ private Button b; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b=(Button) findViewById(R.id.button); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Dialog(); } }); } private void Dialog() { new AlertDialog.Builder(this).setTitle("请输入").setIcon( android.R.drawable.ic_dialog_info).setView( new EditText(this)).setPositiveButton("确定", null) .setNegativeButton("取消", null).show(); } }
例四:信息内容是一组单选框
下面是MainActivity.java主界面文件:
public class MainActivity extends Activity{ private Button b; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b=(Button) findViewById(R.id.button); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Dialog(); } }); } private void Dialog() { new AlertDialog.Builder(this).setTitle("单选框").setIcon( android.R.drawable.ic_dialog_info).setSingleChoiceItems( new String[] { "男", "女" }, 0,//0默认选中男,1默认女 new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setNegativeButton("取消", null).show(); } }
例五:信息内容是一组多选框
下面是MainActivity.java主界面文件:
public class MainActivity extends Activity{ private Button b; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b=(Button) findViewById(R.id.button); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Dialog(); } }); } private void Dialog() { new AlertDialog.Builder(this).setTitle("复选框").setMultiChoiceItems( new String[] { "Item1", "Item2" }, null, null) .setPositiveButton("确定", null) .setNegativeButton("取消", null).show(); } }
本讲就到这里,Take
your time and enjoy it
标签:android style blog http ar color os sp java
原文地址:http://blog.csdn.net/liguojin1230/article/details/41344413