popupwindo

package cn.itcast.popupwindow;


import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;


public class DemoActivity extends Activity {
    /** Called when the activity is first created. */
private LinearLayout ll;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ll = (LinearLayout) findViewById(R.id.ll);
    }
    
    public void click(View view){
    TextView contentView = new TextView(this);
    contentView.setText("我是弹出的文本");
    contentView.setTextSize(30);
//     contentView.setBackgroundColor(Color.GRAY);

   


PopupWindow popup = new PopupWindow(contentView, 200, 100, true);

    //注意:popupwindow 一定要设置背景资源.
   
    popup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

   

popup.showAtLocation(ll, Gravity.LEFT | Gravity.TOP, 0, 30);

    }

}


生命周期:

当界面上第一个widget被创建的时候
10-15 06:15:34.239: INFO/System.out(1338): onreceive
10-15 06:15:34.239: INFO/System.out(1338): onenable   非常适合做widget的初始化的操作.
10-15 06:15:34.250: INFO/System.out(1338): onreceive
10-15 06:15:34.250: INFO/System.out(1338): onupdate


当第二个widget被创建
10-15 06:16:27.081: INFO/System.out(1338): onreceive
10-15 06:16:27.081: INFO/System.out(1338): onupdate


当三个widget被创建
10-15 06:16:49.141: INFO/System.out(1338): onreceive
10-15 06:16:49.141: INFO/System.out(1338): onupdate




当widget被移除
10-15 06:17:11.761: INFO/System.out(1338): onreceive
10-15 06:17:11.761: INFO/System.out(1338): ondelete


当最后一个widget被移除
10-15 06:17:35.422: INFO/System.out(1338): onreceive
10-15 06:17:35.422: INFO/System.out(1338): ondelete
10-15 06:17:35.431: INFO/System.out(1338): onreceive
10-15 06:17:35.431: INFO/System.out(1338): ondisable  适合做widget的清理操作.


因为widget是运行在另外一个应用程序里面 ,所以他的生命周期 其实是由另外的应用程序所管理.
qq桌面 go桌面 awt桌面 360桌面.
onenable() 第一次被创建的时候
ondisable() 最后一个条目被移除的时候调用.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值