自定义警告框 [英] Custom Alert Box

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

问题描述

我想一个警告框,这是在短期完全自定义,我想对我的背景图片,我的自定义按钮,并在其上​​我的自定义消息,使用具有只是我的消息的默认警告框目前即时通讯,但我希望它是完全自正如我所说的警告框前面

请帮我,如果它的可能的,请分享样本code片段
thnks:)

目前的code是这样的: -

  AlertDialog.Builder alertDialogBu​​ilder3 =新AlertDialog.Builder(背景);
                alertDialogBu​​ilder3.setTitle(位置查核);
                alertDialogBu​​ilder3
                .setMessage(你要取消加载?)
                .setCancelable(假)
                .setPositiveButton(OK,新DialogInterface.OnClickListener(){
                    公共无效的onClick(DialogInterface对话,诠释的id){                        LAtestTab.this.finish();
                    }
                })
                .setNegativeButton(否,新DialogInterface.OnClickListener(){
                    公共无效的onClick(DialogInterface对话,诠释的id){
                        //如果单击此按钮,只要关闭
                        //对话框,什么也不做
                        dialog.cancel();
                    }
                });
                ;                AlertDialog alertDialog3 = alertDialogBu​​ilder3.create();                alertDialog3.show();


解决方案

下面就是Java code ....

  exit.setOnClickListener(新OnClickListener()
{
     @覆盖
     公共无效的onClick(查看arg0中)
    {
            最后一个对话框dialog1 =新的对话框(CatchTheCatActivity.this);
            dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog1.setContentView(R.layout.custom_alert);            按钮是=(按钮)dialog1.findViewById(R.id.button1);
            按钮没有=(按钮)dialog1.findViewById(R.id.button2);            yes.setOnClickListener(新OnClickListener()
            {
                @覆盖
                公共无效的onClick(视图v)
                {
                    完();
                }
            });
            no.setOnClickListener(新OnClickListener()
            {
                @覆盖
                公共无效的onClick(视图v)
                {
                        dialog1.dismiss();                }
            });
            dialog1.show();
   }
});

下面是XML文件...(custom_alert)

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =110dp
    机器人:背景=@绘制/ BG
    机器人:方向=垂直>    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=垂直机器人:比重=中心>
        < ImageView的
            机器人:ID =@ + ID / imageView1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginTop =5DP
            机器人:SRC =@绘制/ TextMessage中/>    < / LinearLayout中>
    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginTop =10dp
        机器人:比重=中心|底>        <按钮
            机器人:ID =@ + ID /按钮1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@绘制/ yes_button/>
        <按钮
            机器人:ID =@ + ID /按钮2
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginLeft =20dp
            机器人:背景=@绘制/ no_button/>    < / LinearLayout中>< / LinearLayout中>

I want an alert box which is fully customized in short i want my background image on that, my custom buttons and my custom message on it, currently i m using a default alert box having my message only but i want it to be fully custom alert box as i said earlier

please help me, and please share a sample code snippet if its possible thnks :)

currently the code is like that :-

AlertDialog.Builder alertDialogBuilder3 = new AlertDialog.Builder(context);
                alertDialogBuilder3.setTitle("Location Check");
                alertDialogBuilder3
                .setMessage("Do you want to cancel loading?")
                .setCancelable(false)
                .setPositiveButton("Ok",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {

                        LAtestTab.this.finish();
                    }
                })
                .setNegativeButton("No",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        // if this button is clicked, just close
                        // the dialog box and do nothing
                        dialog.cancel();
                    }
                });
                ;

                AlertDialog alertDialog3 = alertDialogBuilder3.create();

                alertDialog3.show();

解决方案

Here is Java Code....

exit.setOnClickListener(new OnClickListener() 
{   
     @Override
     public void onClick(View arg0) 
    {
            final Dialog dialog1 = new Dialog(CatchTheCatActivity.this);
            dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog1.setContentView(R.layout.custom_alert);

            Button yes = (Button) dialog1.findViewById(R.id.button1);
            Button no = (Button) dialog1.findViewById(R.id.button2);

            yes.setOnClickListener(new OnClickListener()
            {
                @Override
                public void onClick(View v) 
                {
                    finish();   
                }
            });
            no.setOnClickListener(new OnClickListener()
            {
                @Override
                public void onClick(View v) 
                {
                        dialog1.dismiss();  

                }
            });
            dialog1.show();
   }
});

here is the XML file... (custom_alert)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="110dp"
    android:background="@drawable/bg"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" android:gravity="center">


        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:src="@drawable/textmessage" />

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center|bottom" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/yes_button"/>


        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:background="@drawable/no_button" />

    </LinearLayout>

</LinearLayout>

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

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