首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

popupWindow的应用

2012-07-02 
popupWindow的使用1.定义一个Popupwindow:private PopupWindow popWinOfKeyboardprivate LayoutInflater

popupWindow的使用

1.定义一个Popupwindow:

private PopupWindow popWinOfKeyboard;private LayoutInflater inflater ;

?

2.onCreate()

  inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);        View layout = inflater.inflate(R.layout.keyboard, null);                popWinOfKeyboard = new PopupWindow(layout, 480, 350);//设置popupwindow的宽高        popWinOfKeyboard.setAnimationStyle(R.style.PopupAnimation);        popWinOfKeyboard.setOutsideTouchable(true);//设置点击PopopWindow的其他位置的时候关闭,无效!!                View myPopView = popWinOfKeyboard.getContentView();//这个很重要!没有这个就找不到,就会nullpoint                dialNum0 = (ImageButton)myPopView.findViewById(R.id.dial_num_0);dialNum1 = (ImageButton)myPopView.findViewById(R.id.dial_num_1);dialNum2 = (ImageButton)myPopView.findViewById(R.id.dial_num_2);               //................               dialNum0.setOnClickListener(this);dialNum1.setOnClickListener(this);dialNum2.setOnClickListener(this);               //..............
?

3.显示

@Overridepublic void onAttachedToWindow(){//放在这里面比较给力啊super.onAttachedToWindow();popWinOfKeyboard.showAtLocation(tvTitleText, Gravity.CENTER, 0, 145);//这里的布局可能有问题!!!}

?

4.关闭

popWinOfKeyboard.dismiss();
?

?

热点排行