Titanium对话框各种形式

Titanium.UI.AlertDialog

proxy
Platform Since
android 0.8
iphone 0.8
ipad 0.8
mobileweb 1.8

Summary

 

An alert dialog is a modal view that includes an optional title, a message and buttons, positioned in the middle of the display.

 

Description

 

An alert dialog is created using Titanium.UI.createAlertDialog.

Although this dialog always appears in the middle of the display (not touching the edges), other aspects of its aesthetics and the way the user interacts with it are different for each platform, as described below.

Android

On Android, the default alert dialog displays text information, via a title and message, without any buttons. As the user can use the system hardware back button to dismiss it, a button is optional.

Buttons are shown if the buttonNames property is defined, and are rendered horizontally below the message.

To create a custom layout, a view may be added and, in turn, a hierarchy of views added to that child view.

iOS

On iOS, the default alert dialog displays text information, via a title and message, with a single button to allow it to be dismissed.

Buttons are defined using the buttonNames property and are rendered vertically below the message.

On iOS 4.0 and later, alert dialogs are automatically cancelled when the application is paused/suspended.

Global Alias

A global method alert() is aliased to this object, and can be invoked with a single message. For example

alert('this is a message');

This will generate an alert with a title of "Alert" and an "OK" button.

Caveats

Multiple alerts should not be shown at once.

 

 

 

 

 

Properties

 

Name Type Summary
androidView String

 

View to load inside the message area, to create a custom layout.

 

buttonNames String

 

Name of each button to create.

 

cancel String

 

Index to define the button cancel button, returned by the click event.

 

message String

 

Dialog message.

 

messageid String

 

Key identifying a string in the locale file to use for the message text.

 

ok String

 

Text for the OK button.

 

okid String

 

Key identifying a string in the locale file to use for the ok text.

 

title String

 

Title of the dialog.

 

titleid String

 

Key identifying a string in the locale file to use for the title text.

 

 

1.确认对话框

    // test firing 2 alerts in a row, should show the
	// first and after you click OK, should then show the next
	var a = Titanium.UI.createAlertDialog({
		title:'添加人员信息',
		message:"人员添加成功",
		buttonNames: ['确定']
	});
	//a.addEventListener('click', function(e) {
	//	alert("Now you should see this one, assuming you dismissed the first alert");
	//});
	a.show();

 

 Titanium对话框各种形式

 

 

2.可选对话框

    var dialog = Titanium.UI.createOptionDialog({
     title: '添加人员信息',
     options: ['成功','失败'],
     cancel:1
 });
 dialog.show();

 

 Titanium对话框各种形式

 

 

4.自定义对话框

	
	var minDate = new Date();
	minDate.setFullYear(2009);
	minDate.setMonth(0);
	minDate.setDate(1);

	var maxDate = new Date();
	maxDate.setFullYear(2009);
	maxDate.setMonth(11);
	maxDate.setDate(31);

	var value = new Date();
	value.setFullYear(2009);
	value.setMonth(0);
	value.setDate(1);


	var view=Ti.UI.createView({
		height:100,
		width:100
	});
	var picker = Ti.UI.createPicker({
		type:Ti.UI.PICKER_TYPE_DATE_AND_TIME,
		minDate:minDate,
		maxDate:maxDate,
		value:value
	});

	// turn on the selection indicator (off by default)
	picker.selectionIndicator = true;
	
	view.add(picker);

  	var dialog = Titanium.UI.createAlertDialog({
		title:'添加人员信息',
		message:"人员添加成功",
	    androidView:view
	});
	dialog.show();

 

 效果如下:

Titanium对话框各种形式

 

 

 

发送邮件对话框

	var emailDialog = Titanium.UI.createEmailDialog();
		if (!emailDialog.isSupported()) {
		Ti.UI.createAlertDialog({
			title:'Error',
			message:'Email not available'
		}).show();
		return;
		}
		emailDialog.setSubject('Hello from Titanium!');
		emailDialog.setToRecipients(['[email protected]']);
		emailDialog.setCcRecipients(['[email protected]']);
		emailDialog.setBccRecipients(['[email protected]']);
		
		if (Ti.Platform.name == 'iPhone OS') {
			emailDialog.setMessageBody('<b>Appcelerator Titanium Rocks!</b>å');
			emailDialog.setHtml(true);
			emailDialog.setBarColor('#336699');
		} else {
			emailDialog.setMessageBody('Appcelerator Titanium Rocks!');
		}

		// attach a blob
		emailDialog.addAttachment(event.media);
		
		// attach a file
		var f = Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'cricket.wav');
		emailDialog.addAttachment(f);
		
		emailDialog.addEventListener('complete',function(e)
		{
			if (e.result == emailDialog.SENT)
			{
				if (Ti.Platform.osname != 'android') {
					// android doesn't give us useful result codes.
					// it anyway shows a toast.
					alert("message was sent");
				}
			}
			else
			{
				alert("message was not sent. result = " + e.result);
			}
		});
		emailDialog.open();
 

你可能感兴趣的:(Titanium)