首页 > 代码库 > Android周笔记(9.8-14)(持续更新)

Android周笔记(9.8-14)(持续更新)

本笔记记录一周内的小知识点和一些心学习的Demo。

1.PopupWindow:

new 一个activity_pop_window:id为popwindow的Button,id为hello123的TextView

自测2.3以下不能实现:

 1 protected void onCreate(Bundle savedInstanceState) { 2         super.onCreate(savedInstanceState); 3         setContentView(R.layout.activity_pop_window); 4         Button btn = (Button) findViewById(R.id.popwindow); 5         final View view = LayoutInflater.from(getApplicationContext()).inflate( 6                 R.layout.popwindoview, null); 7         final PopupWindow pop = new PopupWindow(200, 200); 8         view.findViewById(R.id.hello123).setOnClickListener( 9                 new OnClickListener() {10 11                     @Override12                     public void onClick(View v) {13                         pop.dismiss();14                     }15                 });16         pop.setContentView(view);17         btn.setOnClickListener(new OnClickListener() {18 19             @Override20             public void onClick(View v) {21                 // pop.showAsDropDown(v);22                 int[] pos = new int[2];23                 v.getLocationOnScreen(pos);24                 pop.showAtLocation(v, Gravity.NO_GRAVITY, pos[0], pos[1]);25             }26         });27     }

2.PopupWindow的消失

方法1:通过点击事件OnclickListrener

方法2:设置popupWindow参数:

pop.setOutsideTouchable(true);
pop.setFocusable(true);

Android周笔记(9.8-14)(持续更新)