int anim abc_fade_in 0x7f010000
int anim abc_fade_out 0x7f010001
int anim abc_grow_fade_in_from_bottom 0x7f010002
int anim abc_popup_enter 0x7f010003
int anim abc_popup_exit 0x7f010004
int anim abc_shrink_fade_out_from_bottom 0x7f010005
int anim abc_slide_in_bottom 0x7f010006
int anim abc_slide_in_top 0x7f010007
int anim abc_slide_out_bottom 0x7f010008
int anim abc_slide_out_top 0x7f010009
int anim abc_tooltip_enter 0x7f01000a
int anim abc_tooltip_exit 0x7f01000b
int anim btn_checkbox_to_checked_box_inner_merged_animation 0x7f01000c
int anim btn_checkbox_to_checked_box_outer_merged_animation 0x7f01000d
int anim btn_checkbox_to_checked_icon_null_animation 0x7f01000e
int anim btn_checkbox_to_unchecked_box_inner_merged_animation 0x7f01000f
int anim btn_checkbox_to_unchecked_check_path_merged_animation 0x7f010010
int anim btn_checkbox_to_unchecked_icon_null_animation 0x7f010011
int anim btn_radio_to_off_mtrl_dot_group_animation 0x7f010012
int anim btn_radio_to_off_mtrl_ring_outer_animation 0x7f010013
int anim btn_radio_to_off_mtrl_ring_outer_path_animation 0x7f010014
int anim btn_radio_to_on_mtrl_dot_group_animation 0x7f010015
int anim btn_radio_to_on_mtrl_ring_outer_animation 0x7f010016
int anim btn_radio_to_on_mtrl_ring_outer_path_animation 0x7f010017
int anim design_bottom_sheet_slide_in 0x7f010018
int anim design_bottom_sheet_slide_out 0x7f010019
int anim design_snackbar_in 0x7f01001a
int anim design_snackbar_out 0x7f01001b
int anim fragment_close_enter 0x7f01001c
int anim fragment_close_exit 0x7f01001d
int anim fragment_fade_enter 0x7f01001e
int anim fragment_fade_exit 0x7f01001f
int anim fragment_fast_out_extra_slow_in 0x7f010020
int anim fragment_open_enter 0x7f010021
int anim fragment_open_exit 0x7f010022
int animator design_appbar_state_list_animator 0x7f020000
int animator design_fab_hide_motion_spec 0x7f020001
int animator design_fab_show_motion_spec 0x7f020002
int animator mtrl_btn_state_list_anim 0x7f020003
int animator mtrl_btn_unelevated_state_list_anim 0x7f020004
int animator mtrl_chip_state_list_anim 0x7f020005
int animator mtrl_fab_hide_motion_spec 0x7f020006
int animator mtrl_fab_show_motion_spec 0x7f020007
int animator mtrl_fab_transformation_sheet_collapse_spec 0x7f020008
int animator mtrl_fab_transformation_sheet_expand_spec 0x7f020009
int attr actionBarDivider 0x7f030000
int attr actionBarItemBackground 0x7f030001
int attr actionBarPopupTheme 0x7f030002
int attr actionBarSize 0x7f030003
int attr actionBarSplitStyle 0x7f030004
int attr actionBarStyle 0x7f030005
int attr actionBarTabBarStyle 0x7f030006
int attr actionBarTabStyle 0x7f030007
int attr actionBarTabTextStyle 0x7f030008
int attr actionBarTheme 0x7f030009
int attr actionBarWidgetTheme 0x7f03000a
int attr actionButtonStyle 0x7f03000b
int attr actionDropDownStyle 0x7f03000c
int attr actionLayout 0x7f03000d
int attr actionMenuTextAppearance 0x7f03000e
int attr actionMenuTextColor 0x7f03000f
int attr actionModeBackground 0x7f030010
int attr actionModeCloseButtonStyle 0x7f030011
int attr actionModeCloseDrawable 0x7f030012
int attr actionModeCopyDrawable 0x7f030013
int attr actionModeCutDrawable 0x7f030014
int attr actionModeFindDrawable 0x7f030015
int attr actionModePasteDrawable 0x7f030016
int attr actionModePopupWindowStyle 0x7f030017
int attr actionModeSelectAllDrawable 0x7f030018
int attr actionModeShareDrawable 0x7f030019
int attr actionModeSplitBackground 0x7f03001a
int attr actionModeStyle 0x7f03001b
int attr actionModeWebSearchDrawable 0x7f03001c
int attr actionOverflowButtonStyle 0x7f03001d
int attr actionOverflowMenuStyle 0x7f03001e
int attr actionProviderClass 0x7f03001f
int attr actionViewClass 0x7f030020
int attr activityChooserViewStyle 0x7f030021
int attr alertDialogButtonGroupStyle 0x7f030022
int attr alertDialogCenterButtons 0x7f030023
int attr alertDialogStyle 0x7f030024
int attr alertDialogTheme 0x7f030025
int attr allowStacking 0x7f030026
int attr alpha 0x7f030027
int attr alphabeticModifiers 0x7f030028
int attr arrowHeadLength 0x7f030029
int attr arrowShaftLength 0x7f03002a
int attr autoCompleteTextViewStyle 0x7f03002b
int attr autoSizeMaxTextSize 0x7f03002c
int attr autoSizeMinTextSize 0x7f03002d
int attr autoSizePresetSizes 0x7f03002e
int attr autoSizeStepGranularity 0x7f03002f
int attr autoSizeTextType 0x7f030030
int attr background 0x7f030031
int attr backgroundSplit 0x7f030032
int attr backgroundStacked 0x7f030033
int attr backgroundTint 0x7f030034
int attr backgroundTintMode 0x7f030035
int attr barLength 0x7f030036
int attr behavior_autoHide 0x7f030037
int attr behavior_fitToContents 0x7f030038
int attr behavior_hideable 0x7f030039
int attr behavior_overlapTop 0x7f03003a
int attr behavior_peekHeight 0x7f03003b
int attr behavior_skipCollapsed 0x7f03003c
int attr borderWidth 0x7f03003d
int attr borderlessButtonStyle 0x7f03003e
int attr bottomAppBarStyle 0x7f03003f
int attr bottomNavigationStyle 0x7f030040
int attr bottomSheetDialogTheme 0x7f030041
int attr bottomSheetStyle 0x7f030042
int attr boxBackgroundColor 0x7f030043
int attr boxBackgroundMode 0x7f030044
int attr boxCollapsedPaddingTop 0x7f030045
int attr boxCornerRadiusBottomEnd 0x7f030046
int attr boxCornerRadiusBottomStart 0x7f030047
int attr boxCornerRadiusTopEnd 0x7f030048
int attr boxCornerRadiusTopStart 0x7f030049
int attr boxStrokeColor 0x7f03004a
int attr boxStrokeWidth 0x7f03004b
int attr buttonBarButtonStyle 0x7f03004c
int attr buttonBarNegativeButtonStyle 0x7f03004d
int attr buttonBarNeutralButtonStyle 0x7f03004e
int attr buttonBarPositiveButtonStyle 0x7f03004f
int attr buttonBarStyle 0x7f030050
int attr buttonCompat 0x7f030051
int attr buttonGravity 0x7f030052
int attr buttonIconDimen 0x7f030053
int attr buttonPanelSideLayout 0x7f030054
int attr buttonStyle 0x7f030055
int attr buttonStyleSmall 0x7f030056
int attr buttonTint 0x7f030057
int attr buttonTintMode 0x7f030058
int attr cardBackgroundColor 0x7f030059
int attr cardCornerRadius 0x7f03005a
int attr cardElevation 0x7f03005b
int attr cardMaxElevation 0x7f03005c
int attr cardPreventCornerOverlap 0x7f03005d
int attr cardUseCompatPadding 0x7f03005e
int attr cardViewStyle 0x7f03005f
int attr checkboxStyle 0x7f030060
int attr checkedChip 0x7f030061
int attr checkedIcon 0x7f030062
int attr checkedIconEnabled 0x7f030063
int attr checkedIconVisible 0x7f030064
int attr checkedTextViewStyle 0x7f030065
int attr chipBackgroundColor 0x7f030066
int attr chipCornerRadius 0x7f030067
int attr chipEndPadding 0x7f030068
int attr chipGroupStyle 0x7f030069
int attr chipIcon 0x7f03006a
int attr chipIconEnabled 0x7f03006b
int attr chipIconSize 0x7f03006c
int attr chipIconTint 0x7f03006d
int attr chipIconVisible 0x7f03006e
int attr chipMinHeight 0x7f03006f
int attr chipSpacing 0x7f030070
int attr chipSpacingHorizontal 0x7f030071
int attr chipSpacingVertical 0x7f030072
int attr chipStandaloneStyle 0x7f030073
int attr chipStartPadding 0x7f030074
int attr chipStrokeColor 0x7f030075
int attr chipStrokeWidth 0x7f030076
int attr chipStyle 0x7f030077
int attr closeIcon 0x7f030078
int attr closeIconEnabled 0x7f030079
int attr closeIconEndPadding 0x7f03007a
int attr closeIconSize 0x7f03007b
int attr closeIconStartPadding 0x7f03007c
int attr closeIconTint 0x7f03007d
int attr closeIconVisible 0x7f03007e
int attr closeItemLayout 0x7f03007f
int attr collapseContentDescription 0x7f030080
int attr collapseIcon 0x7f030081
int attr collapsedTitleGravity 0x7f030082
int attr collapsedTitleTextAppearance 0x7f030083
int attr color 0x7f030084
int attr colorAccent 0x7f030085
int attr colorBackgroundFloating 0x7f030086
int attr colorButtonNormal 0x7f030087
int attr colorControlActivated 0x7f030088
int attr colorControlHighlight 0x7f030089
int attr colorControlNormal 0x7f03008a
int attr colorError 0x7f03008b
int attr colorPrimary 0x7f03008c
int attr colorPrimaryDark 0x7f03008d
int attr colorSecondary 0x7f03008e
int attr colorSwitchThumbNormal 0x7f03008f
int attr commitIcon 0x7f030090
int attr contentDescription 0x7f030091
int attr contentInsetEnd 0x7f030092
int attr contentInsetEn
Xamarin.Andorid实现对话框
需积分: 0 47 浏览量
更新于2022-11-19
收藏 45.75MB 7Z 举报
在Xamarin.Android开发中,有时候我们需要向用户展示一些临时性的信息或者需要用户做出选择时,对话框(Dialog)是一个常用且重要的组件。本教程将详细讲解如何使用AlertDialog来实现Xamarin.Android中的弹框功能,包括系统自带的对话框以及自定义样式的对话框。
让我们了解`AlertDialog`的基本用法。`AlertDialog`是Android SDK提供的一个内置组件,它可以在屏幕中心显示一个具有标题、消息、按钮等元素的弹出窗口。在Xamarin.Android中,我们可以通过`AlertDialog.Builder`类来构建一个对话框。以下是一个简单的示例:
```csharp
using Android.App;
using Android.Content;
// ...
public class MainActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// ...
// 创建一个AlertDialog.Builder实例
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// 设置对话框的标题
builder.SetTitle("对话框示例");
// 设置对话框的消息内容
builder.SetMessage("这是一个基本的对话框示例。");
// 添加确认按钮,并指定点击后的回调
builder.SetPositiveButton("确定", (sender, e) =>
{
Toast.MakeText(this, "你点击了确定按钮", ToastLength.Short).Show();
});
// 创建并显示对话框
AlertDialog dialog = builder.Create();
dialog.Show();
}
}
```
上述代码展示了如何创建一个带有标题和消息的对话框,以及添加了一个确认按钮。当用户点击“确定”按钮时,会显示一个Toast通知。
然而,Android允许开发者自定义对话框的样式,以满足更丰富的交互需求。这通常涉及到自定义布局文件,然后将其设置到`AlertDialog`上。例如,我们可以创建一个XML布局文件(如`dialog_custom.xml`),然后在代码中加载并应用:
```xml
<!-- 在res/layout/dialog_custom.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/tvDialogTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="自定义对话框"
android:textSize="18sp" />
<TextView
android:id="@+id/tvDialogContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="这是一个自定义样式的对话框。" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="16dp">
<Button
android:id="@+id/btnCancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="取消" />
<Button
android:id="@+id/btnOk"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="确定" />
</LinearLayout>
</LinearLayout>
```
接着在代码中加载并使用这个布局:
```csharp
// 加载自定义布局
LayoutInflater inflater = LayoutInflater.From(this);
View customView = inflater.Inflate(Resource.Layout.dialog_custom, null);
// 获取自定义布局中的控件
TextView tvDialogTitle = customView.FindViewById<TextView>(Resource.Id.tvDialogTitle);
TextView tvDialogContent = customView.FindViewById<TextView>(Resource.Id.tvDialogContent);
Button btnCancel = customView.FindViewById<Button>(Resource.Id.btnCancel);
Button btnOk = customView.FindViewById<Button>(Resource.Id.btnOk);
// 绑定事件
btnCancel.Click += (sender, e) => dialog.Dismiss();
btnOk.Click += (sender, e) =>
{
Toast.MakeText(this, "你点击了确定按钮", ToastLength.Short).Show();
dialog.Dismiss();
};
// 使用自定义布局创建对话框
AlertDialog.Builder customBuilder = new AlertDialog.Builder(this);
customBuilder.SetView(customView);
customBuilder.SetTitle("");
customBuilder.SetNegativeButton("取消", (sender, e) => dialog.Dismiss());
customBuilder.SetPositiveButton("确定", (sender, e) =>
{
Toast.MakeText(this, "你点击了确定按钮", ToastLength.Short).Show();
dialog.Dismiss();
});
AlertDialog customDialog = customBuilder.Create();
customDialog.Show();
```
以上就是使用`AlertDialog`在Xamarin.Android中实现对话框的基本方法,包括系统默认样式和自定义样式。通过灵活运用,开发者可以根据项目需求创建各种复杂功能的对话框,提高用户体验。在实际开发中,还可以结合其他组件,如Spinner、EditText等,以实现更多交互场景。在`XamarinDialogDemo`这个项目中,你可以找到这些示例的完整实现,进一步学习和参考。
zlbcdn
- 粉丝: 156
- 资源: 22
最新资源
- 毕设和企业适用springboot智慧交通平台类及物流管理平台源码+论文+视频.zip
- 毕设和企业适用springboot智慧交通平台类及信息管理系统源码+论文+视频.zip
- 毕设和企业适用springboot智慧交通平台类及远程教育平台源码+论文+视频.zip
- 毕设和企业适用springboot智慧交通平台类及虚拟现实体验平台源码+论文+视频.zip
- 毕设和企业适用springboot智慧交通平台类及用户行为分析平台源码+论文+视频.zip
- 毕设和企业适用springboot智慧交通平台类及职业技能培训平台源码+论文+视频.zip
- 毕设和企业适用springboot智慧交通平台类及智能客服系统源码+论文+视频.zip
- 毕设和企业适用springboot智慧交通平台类及智能农场管理系统源码+论文+视频.zip
- 毕设和企业适用springboot智慧交通平台类及自动化测试平台源码+论文+视频.zip
- 毕设和企业适用springboot智慧教育平台类及AR技术平台源码+论文+视频.zip
- 毕设和企业适用springboot智慧交通平台类及智能图像识别系统源码+论文+视频.zip
- 毕设和企业适用springboot智慧教育平台类及共享经济平台源码+论文+视频.zip
- 毕设和企业适用springboot智慧教育平台类及大数据云平台源码+论文+视频.zip
- 毕设和企业适用springboot智慧教育平台类及电子产品维修平台源码+论文+视频.zip
- 毕设和企业适用springboot智慧教育平台类及健康数据分析系统源码+论文+视频.zip
- 5Pin插针设备工程图机械结构设计图纸和其它技术资料和技术方案非常好100%好用.zip