创建自定义对话框 [英] Create Custom Dialog

查看:133
本文介绍了创建自定义对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建自定义对话框像下面的图片可以从一个活动,同时执行验证调用。

I wanted to create Custom Dialog like the following image which can be called from an activity while performing validations.

在自定义对话框应该是一个单独的类。

The Custom Dialog should be a separate class.

我如何能实现自定义对话框下面。我给通过以下网址了。

How can I achieve the following the custom dialog. I gave gone through the following url

http://developer.android.com/guide/topics/ui/ dialogs.html

但无法得到我应该如何创建低于警戒一个清晰的概念。

but unable to get a clear idea on how should I create the below alert .


  1. 我如何创建自己的头警报信息与背景颜色和放大器;文本警报信息前面的图标

  1. How can I create my own header "Alert Info" with a background color & an icon before the text "Alert Info"

我想也控制警报(90%的透明度)的透明度
是否有可能实现在Android%的透明度

I wanted to also control the transparency of the alert (90 % transparency) Is it possible to achieve % transparency on Android

如何提供听众的按钮确定和放大器;取消。

How to provide the listeners to the buttons Ok & Cancel.

任何样品code。与布局XML处理上述要求会有所帮助。
请提供样品code /建议。

Any sample code with layout xml handling the above requirements will be helpful. Kindly provide with a sample code/suggestions.

推荐答案

您只需要在对话框中创建一个自定义布局,然后手动关联了控制。这应该让你开始。

You just need to create a custom layout for the dialog then wire up the controls manually.. this should get you started.

customdialoglayout.xml

customdialoglayout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ImageView ... />
        <TextView android:text="Alert Info" ... />
    </LinearLayout>
    <!-- Additional Content Here -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <Button android:id="@+id/btnOkay" android:text="Ok" ...></Button>
        <Button android:id="@+id/btnCancel" android:text="Cancel" ...></Button>
    </LinearLayout>
</LinearLayout>

设置自定义布局的对话框初始化后..

Set the custom layout to the dialog after initializing..

dialog.setContentView(R.layout.customdialoglayout);

要连接你的处理器,你将不得不做一些事来的效果。

To wire up your handlers you will have to do something to the effect of..

Button myButton = (Button)dialog.findViewById(R.id.btnOkay);

我张贴只是截断作为一个例子中的XML,额外的自定义样式将需要获得所需的造型,当然更换所需的实际属性的省略号,但你可以看到你想要实现的目标是很简单。

The XML I posted is truncated just as an example, additional custom styling will be needed to achieve the desired look and of course replace the ellipses with the actual attributes that you want, but as you can see what you want to accomplish is fairly simple.

这篇关于创建自定义对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆