Titanium对话框各种形式

Titanium.UI.AlertDialog

proxy
PlatformSince
android0.8
iphone0.8
ipad0.8
mobileweb1.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

 

NameTypeSummary
androidViewString

 

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

 

buttonNamesString

 

Name of each button to create.

 

cancelString

 

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

 

messageString

 

Dialog message.

 

messageidString

 

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

 

okString

 

Text for the OK button.

 

okidString

 

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

 

titleString

 

Title of the dialog.

 

titleidString

 

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();

 

 

 

 

2.可选对话框

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

 

 

 

 

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();

 

 效果如下:

 

 

 

发送邮件对话框

	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(['foo@yahoo.com']);
		emailDialog.setCcRecipients(['bar@yahoo.com']);
		emailDialog.setBccRecipients(['blah@yahoo.com']);
		
		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();
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值