1.android对话框实现方法。
Dialog dialog=new Dialog(MainActivity.this);
dialog.setContentView(R.layout.dialog_layout);
TextView textView= (TextView)dialog.findViewById(R.id.dialogtxtid);
textView.setText("Hello World");
dialog.setTitle("Custom Dialog");
dialog.show();
这里也是自定义了layout(可以访问layout中的控件),不带有标题(注释代码)且有两个按钮的对话框。
// TODO Auto-generated method stub
AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
//set icon, title, message.
//builder.setIcon(R.drawable.icon1);set icon, title, message.
//builder.setTitle("Question");
//builder.setMessage(R.string.about_content);
LayoutInflater inflater=LayoutInflater.from(MainActivity.this);
View textView= inflater.inflate(R.layout.dialog_layout, null);
builder.setView(textView);
TextView text = (TextView) textView.findViewById(R.id.dialogtxtid);
text.setText("Hello, this is a custom dialog!");
builder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
setTitle("You'v clicked comfirm.");
}
});
builder.setNegativeButton("Cancle", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
setTitle("");
}
});
builder.show();
android中还有个PopupWindow
设置TextView控件字体格式。
字体居中:android:gravity="center"; layout_gravity是指控件的位置;gravity是指内部内容的位置。
字体行距:android:lineSpacingExtra="3dp" 或者android:lineSpacingMultiplier="1.2"