Android有趣的全透明效果--Activity及Dialog的全透明3(转载)

本文介绍了一个使用Android创建自定义对话框的例子。通过继承Activity并设置布局文件,文章展示了如何响应按钮点击事件来显示带有特定头部信息、内容和取消按钮的对话框。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

4.Activity代码如下:

lain

  1. package lab.sodino.tanc;  
  2. import android.app.Activity;  
  3. import android.app.Dialog;  
  4. import android.os.Bundle;  
  5. import android.view.View;  
  6. import android.widget.Button;  
  7. import android.widget.TextView;  
  8. public class TANCAct extends Activity {  
  9.     /** Called when the activity is first created. */  
  10.     @Override  
  11.     public void onCreate(Bundle savedInstanceState) {  
  12.         super.onCreate(savedInstanceState);  
  13.         setContentView(R.layout.main);  
  14.         Button btnShow = (Button) findViewById(R.id.btnShow);  
  15.         btnShow.setOnClickListener(new Button.OnClickListener() {  
  16.             public void onClick(View view) {  
  17.                 showTANC(  
  18.                         "This is my custom dialog box",  
  19.                         "TextContent/nWhen a dialog is requested for the first time, Android calls onCreateDialog(int)  from your Activity, which is where you should instantiate the Dialog. This callback method is passed the same ID that you passed to showDialog(int). After you create the Dialog, return the object at the end of the method.",  
  20.                         "http://blog.youkuaiyun.com/sodino");  
  21.             }  
  22.         });  
  23.     }  
  24.     private void showTANC(String header, String content, String url) {  
  25.         final Dialog dialog = new Dialog(this, R.style.TANCStyle);  
  26.         dialog.setContentView(R.layout.main_dialog);  
  27.         dialog.setTitle(header);  
  28.         dialog.setCancelable(true);  
  29.         TextView textView01 = (TextView) dialog.findViewById(R.id.TextView01);  
  30.         textView01.setText(content + content + content);  
  31.         Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);  
  32.         btnCancel.setOnClickListener(new Button.OnClickListener() {  
  33.             public void onClick(View view) {  
  34.                 dialog.cancel();  
  35.             }  
  36.         });  
  37.         dialog.show();  
  38.     }  
  39. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七斗星

赏点银子去植发

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值