PopupWindow(懸浮框)
Android的對話框有兩種:AlertDialog和PopupWindow飞蚓。它們的不同點(diǎn)在于:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?AlertDialog的位置固定玷坠,是非阻塞線程的劲藐,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?PopupWindow位置隨意樟凄,是阻塞線程的。
1.常用方法
? ? ? ? ? ? ?setContentView(View contentView):設(shè)置PopupWindow顯示的View
? ? ? ? ? ? ?getContentView():獲得PopupWindow顯示的View
? ? ? ? ? ? ?setAnimationStyle(int):設(shè)置動畫效果
? ? ? ? ? ? ?showAsDropDown(View anchor):相對某個控件的位置(正左下方)汰现,無偏移
? ? ? ? ? ? ?showAsDropDown(View anchor, int xoff, int yoff):相對某個控件的位置叔壤,有偏移
? ? ? ? ? ? ?showAtLocation(View parent, int gravity, int x, int y):相對于父控件的位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 可以設(shè)置偏移或無偏移
? ? ? ? ? ? ?setTouchable(boolean touchable):設(shè)置PopupWindow是否響應(yīng)touch事件嗅战,默認(rèn)是true
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 如果設(shè)置為false俺亮,所有PopupWindow上的touch事件無響應(yīng)
? ? ? ? ? ? ?setFocusable(boolean):是否具有獲取焦點(diǎn)的能力,默認(rèn)為false
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1.如果為false东且,editText等控件將無法獲取焦點(diǎn)(不可編輯)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?2.如果為true本讥,即pop獲取焦點(diǎn)鲁冯,返回鍵被攔截(如果setBackgroundDrawable色查,點(diǎn)擊返回pop.dismiss)
? ? ? ? ? ? ? setOutsideTouchable(boolean):PopupWindow以外的區(qū)域是否可點(diǎn)擊(點(diǎn)擊外部區(qū)域pop.dismiss)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?需mPopWindow.setBackgroundDrawable(newBitmapDrawable());
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (因?yàn)閎g不為null會加一層ViewContainer综慎,并對返回鍵做了處理:點(diǎn)擊pop.dismiss)