自定义dialog 占用整个activity

/* 自定义的dialog */

public class QuitDialog extends Activity implements OnClickListener {

 

    private Button bt_true , bt_false ;

    private TextView content ;

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

       super .onCreate(savedInstanceState);

       requestWindowFeature(Window. FEATURE_NO_TITLE );

       setContentView(R.layout. dialog_b1 );

 

       bt_true = (Button) findViewById(R.id. dialog_b1_true );

       bt_false = (Button) findViewById(R.id. dialog_b1_false );

       content = (TextView) findViewById(R.id. toast_content );

       content .setGravity(Gravity. LEFT );

       content .setPadding(15, 10, 0, 0);

 

       bt_true .setOnClickListener(QuitDialog. this );

       bt_false .setOnClickListener(QuitDialog. this );

       content .setText( " 您确定要退出吗? " );

 

    }

 

    @Override

    public void onClick(View v) {

       switch (v.getId()) {

       case R.id. dialog_b1_true :

           final ActivityManager am = (ActivityManager) QuitDialog. this

                  .getSystemService(Context. ACTIVITY_SERVICE );

           am.restartPackage(QuitDialog. this .getPackageName());

           break ;

       case R.id. dialog_b1_false :

           finish();

           break ;

       }

    }

 

}

 

/* 自定义dialog xml */

 

<? xml version = "1.0" encoding = "utf-8" ?>

< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"

    android:id = "@+id/toast_layout_root" android:orientation = "vertical"

    android:layout_width = "240dip" android:layout_height = "170dip" >

    < LinearLayout android:layout_width = "180dip"

       android:layout_height = "50dip" android:paddingLeft = "10dp" android:orientation = "horizontal" >

       < ImageView android:id = "@+id/toast_img" android:background = "@drawable/icon0"

           android:layout_width = "wrap_content" android:layout_height = "wrap_content"

           android:layout_marginRight = "10dp" />

       < TextView android:id = "@+id/toast_title" android:text = " 温馨提示 "

           android:layout_width = "wrap_content" android:layout_height = "wrap_content"

           android:layout_gravity = "center_vertical" android:textSize = "22px"

           android:textColor = "#FF34B3" />

    </ LinearLayout >

    < ImageView android:src = "@drawable/line_2"

       android:layout_width = "wrap_content" android:layout_height = "wrap_content"

       android:layout_gravity = "center_horizontal" />

    < TextView android:id = "@+id/toast_content"

       android:layout_width = "wrap_content" android:layout_height = "wrap_content"

       android:layout_marginTop = "10dp" android:textSize = "20px"

       android:textColor = "#ffffff" android:layout_gravity = "center" />

    < LinearLayout android:layout_width = "fill_parent"

       android:layout_height = "wrap_content" android:layout_marginTop = "10dp" android:background = "#949494"

       android:orientation = "vertical" >

       < LinearLayout android:layout_width = "wrap_content"

           android:layout_height = "fill_parent"

           android:orientation = "horizontal" >

           < Button android:id = "@+id/dialog_b1_true" android:text = " 确定 "

              android:textColor = "#5b5b5b" android:textSize = "20px" android:gravity = "center"

              android:layout_width = "100dip" android:layout_height = "wrap_content" android:layout_margin = "10dp"

              android:background = "@drawable/button_selector_3" ></ Button >

           < Button android:id = "@+id/dialog_b1_false" android:text = " 取消 "

              android:textColor = "#5b5b5b" android:textSize = "20px" android:gravity = "center"

              android:layout_width = "100dip" android:layout_height = "wrap_content"

              android:background = "@drawable/button_selector_3" android:layout_margin = "10dp" ></ Button >

       </ LinearLayout >

    </ LinearLayout >

</ LinearLayout >

 

AndroidManifest.xml   声明

< activity android:name = "QuitDialog" android:theme = "@android:style/Theme.Dialog" ></ activity >

 

/*  在主程序中的调用 */

Intent intent = new Intent();

intent.setClass( this , QuitDialog. class );

startActivity(intent);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值