Android 弹出消息提醒——PopupWindow。

public class MainActivity extends Activity {    private PopupWindow pupWindow;    private TextView tv;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }    public void showWindow(){        if(pupWindow == null){             LayoutInflater la = LayoutInflater.from(MainActivity.this);             View view = la.inflate(R.layout.pupwindow, null);//自定义布局             tv = (TextView) view.findViewById(R.pupwindow.txt);             view.setOnClickListener(new OnClickListener() {                    @Override                    public void onClick(View v) {                        pupWindow.dismiss();                    }                });             pupWindow = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);        }        tv.setText("this is pup window!");        //设置PopupWindow的焦点        pupWindow.setFocusable(true);        //点击PopupWindow之外的地方PopupWindow会消失        pupWindow.setOutsideTouchable(true);        //showAtLocation(View parent, int gravity, int x, int y):相对于父控件的位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等),可以设置偏移或无偏移        pupWindow.showAtLocation(MainActivity.this.getWindow().getDecorView(), Gravity.CENTER, 0, 0);        pupWindow.update();    }}

仅用于记录!

更多相关文章

  1. android > 弹出复选框
  2. Android切换横屏竖屏生命周期变化
  3. Android又一个超漂亮的日历控件
  4. Android(安卓)通用标题栏之组合控件
  5. android 全屏幕
  6. Android(安卓)计算控件尺寸
  7. android的常用控件总结【安卓入门五】
  8. Android(安卓)GridView,Gallery动态更新数据
  9. Android用悬浮按钮实现翻页效果

随机推荐

  1. Android(安卓)面试题总结之Android(安卓)
  2. Android(安卓)SDK/ADT 历史版本下载地址
  3. 【置顶】用Eclipse开发Android应用程序索
  4. Android工程的建立与解析
  5. 浅析Android手机卫士保存手机安全号码
  6. android:windowBackground 和 android:ba
  7. Android性能调优
  8. Android(安卓)Studio 系列(二)使用Android(
  9. LinearLayout和RelativeLayout布局中使用
  10. 使用AsyncTask异步更新UI界面