代码来自于APIDemo
1. 最简单的OK/Cancel的弹出框
//创建新的弹出框
new AlertDialog.Builder(AlertDialogSamples.this)
//设置弹出框的图标
.setIcon(R.drawable.alert_dialog_icon)
//弹出框的标题
.setTitle(R.string.alert_dialog_two_buttons_title)
//OK按钮的设置,以及对应的onClick事件
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//onClick事件的具体实现
}
})
//Cancel按钮的设置,以及对应的onClick事件
.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//onClick事件的具体实现
}
})
.create();
效果图:
2. 带有List的弹出框
//创建带有Item的弹出框
return new AlertDialog.Builder(AlertDialogSamples.this)
//设置弹出框的标题
.setTitle(R.string.select_dialog)
//设置item的具体内容,R.array.select_dialog_items是定义在XML中的文件,也可以是new String[]{"a","b" ……}的数组
.setItems(R.array.select_dialog_items, new DialogInterface.OnClickListener() {
//选中Item时产生的事件
public void onClick(DialogInterface dialog, int which) {
/* User clicked so do some stuff */
String[] items = getResources().getStringArray(R.array.select_dialog_items);
new AlertDialog.Builder(AlertDialogSamples.this)
.setMessage("You selected: " + which + " , " + items[which])
//直接显示,显示之前用户没有什么其它的额外操作
.show();
}
})
//显示之前,用户可能有额外的操作
.create();
对应的XML文件:
<xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Used in app/dialog examples -->
<string-array name="select_dialog_items">
<item>Command one</item>
<item>Command two</item>
<item>Command three</item>
<item>Command four</item>
</string-array>
</resources>
效果图:
3. 进度条式的弹出框的实现//创建一个进度条式的弹出框
mProgressDialog = new ProgressDialog(AlertDialogSamples.this);
//设置图标
mProgressDialog.setIcon(R.drawable.alert_dialog_icon);
//设置标题
mProgressDialog.setTitle(R.string.select_dialog);
//设置进度条的显示方式(水平的)
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//设置进度条的最大值
mProgressDialog.setMax(MAX_PROGRESS);
//设置按钮
mProgressDialog.setButton(getText(R.string.alert_dialog_hide), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
mProgressDialog.setButton2(getText(R.string.alert_dialog_cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
效果图:
4. 单选式弹出框的实现
//单选按钮式的弹出框
return new AlertDialog.Builder(AlertDialogSamples.this)
.setIcon(R.drawable.alert_dialog_icon)
.setTitle(R.string.alert_dialog_single_choice)
//设置单选按钮的集合,同理该处可以来自于XML,也可以是String[]{}的实现
.setSingleChoiceItems(R.array.select_dialog_items2, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.create();
效果图:
5. 多选弹出框的实现
//其道理与上相同,只是一个单选一个多选
return new AlertDialog.Builder(AlertDialogSamples.this)
.setIcon(R.drawable.ic_popup_reminder)
.setTitle(R.string.alert_dialog_multi_choice)
.setMultiChoiceItems(R.array.select_dialog_items3,
new boolean[]{false, true, false, true, false, false, false},
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int whichButton,
boolean isChecked) {
}
})
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.create();
效果图:
6. 自定义布局弹出框
//用于加载布局文件
LayoutInflater factory = LayoutInflater.from(this);
//从XML中加载布局
final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
return new AlertDialog.Builder(AlertDialogSamples.this)
.setIcon(R.drawable.alert_dialog_icon)
.setTitle(R.string.alert_dialog_text_entry)
//关键在这里,将这个布局加入到这个弹出框中
.setView(textEntryView)
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */
}
})
.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked cancel so do some stuff */
}
})
.create();
效果图:
uiscrollview是开发sdk自带的控件,
在使用的时候,发现滚动不了,
最常山见的原因是
contentSize 这个属性,比uiscrollview的frame要小。。。所以无需滚动,自然就滚动不了。
scrollenabled 这个属性, 标识着是否允许滚动,要言设成yes
还有一个比较隐蔽的。
如果你的scrollview是放在controller的view里面的。
设置contentSzie的代码不要放在 controller的init方法里面,
可以放在viewdidload里面,这样就可以滚动了,
附上代码:
正确代码
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[superviewDidLoad];
[scrollsetContentSize:CGSizeMake(1280, 480)];
}
错误代码:
- (id)init
{
self = [superinit];
if (self)
{
[scrollsetContentSize:CGSizeMake(1280, 480)];
}
returnself;
}
项
描述
App.xaml / App.xaml.cs
定义应用程序的入口点,初始化应用程序范围内的资源,,显示应用程序用户界面
MainPage.xaml / MainPage.xaml.cs
定义应用程序中的程序页面(带有用户界面的页面)
ApplicationIcon.png
一种带有图标的图像文件,代表了手机应用程序列表中应用程序的图标
Background.png
一种带有图标的图像文件,代表了在开始页面上应用程序的图表
SplashScreenImage.jpg
这个图片会在应用程序第一次被启动时显示。启动画面会给用户一个即时的反馈,告诉用户应用程序正在启动直到成功跳转到应用程序的第一个页面。用户的启动画面可以和应用程序的一个页面设计的非常相似,这样能给使用这一个应用程序被快速加载的感觉。
Properties\AppManifest.xml
一个生成应用程序包所必需的应用程序清单文件
Properties\AssemblyInfo.cs
包含名称和版本的元数据,这些元数据将被嵌入到生成的程序集
Properties\WMAppManifest.xml
一个包含与Windows Phone Silverlight应用程序相关的特定元数据的清单文件,且包含了用于Windows Phone的Silverlight所具有的特定功能
References folder
一些库文件(集)的列表,为应用程序的工作提供功能和服务。
Application 类的RootFrame 属性标识了应用程序的启动页面。 所有的Windows Phone应用程序都有一个最顶层的容器元素,它的数据类型是PhoneApplicationFrame 。这个框架承载了一个或多个用来标识应用程序内容的PhoneApplicationPage 元素,同时它还被用来处理不同页面之间的导航切换。