Package COM. test. ui; import android. app. activity; import android. graphics. drawable. bitmapdrawable; import android. OS. bundle; import android. view. gravity; import android. view. keyevent; import android. view. view; import android. view. view. onclicklistener; import android. view. viewgroup. layoutparams; import android. widget. button; import android. widget. popupwindow; import android. widget. toast; public class testactivi Ty extends activity {private button but_menu; private button open_id; private button save_id; view contentview; private popupwindow m_popupwindow; Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); Init (); setlistener ();} private void Init () {contentview = getlayoutinflater (). inflate (R. layout. popupmenu, null, true); but_menu = (button) findview Byid (R. id. but_menu); open_id = (button) contentview. findviewbyid (R. id. btn_popup_information); save_id = (button) contentview. findviewbyid (R. id. btn_popup_quote); // view displayed in the pop-up window of popupwindow. Parameters 2 and 3: the size of the pop-up window m_popupwindow = new popupwindow (contentview, layoutparams) respectively. fill_parent, layoutparams. wrap_content, true); m_popup?#setbackgrounddrawable (New bitmapdrawable (); // with this sentence, you can click the return (UNDO) button dismiss () popwi Ndowm_popupw.extends setoutsidetouchable (true); m_popupw.extends setanimationstyle (R. style. popupanimation);} private void setlistener () {contentview. setonclicklistener (new view. onclicklistener () {public void onclick (view v) {m_popup1_1_dismiss () ;}}); // m_popupwindow = new popupwindow (); but_menu.setonclicklistener (New onclicklistener () {public void onclick (view v) {try {If (m_popupwing w.isshowing () {m _ Popupwindow. dismiss ();} m_popupdomaindetail showasdropdown (V);} catch (exception e) {toast. maketext (testactivity. this, E. getmessage (), toast. length_short) ;}}}); open_id.setonclicklistener (New onclicklistener () {public void onclick (view v) {m_popuplistener extends dismiss (); toast. maketext (testactivity. this, "opened and triggered", toast. length_short ). show () ;}}); save_id.setonclicklistener (New onclicklistener () {public void onclick (View v) {m_popupdomaindetail dismiss (); toast. maketext (testactivity. this, "Save triggered", toast. length_short ). show () ;}}) ;}public Boolean onkeydown (INT keycode, keyevent event) {If (keycode = keyevent. keycode_back) {If (m_popupwindow! = NULL & m_popupwing w.isshowing () {m_popup00000000dismiss (); Return true ;}} return Super. onkeydown (keycode, event );}}
Popupmenu. xml <? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Id = "@ + ID/lin_main" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: paddingright = "120dip"> <linearlayout Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: Background = "@ drawable/popup_search" Android: orientation = "vertical"> <button Android: Id = "@ + ID/btn_popup_information" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_weight = "1" Android: Background = "@ drawable/goods_bg" Android: text = "open" Android: textcolor = "#000000" Android: textsize = "16sp"/> <button Android: Id = "@ + ID/btn_popup_quote" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_margintop = "5dip" Android: layout_weight = "1" Android: Background = "@ drawable/goods_bg" Android: text = "save" Android: textcolor = "#000000" Android: textsize = "16sp"/> <button Android: Id = "@ + ID/btn_popup_product" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_margintop = "5dip" Android: layout_weight = "1" Android: Background = "@ drawable/goods_bg" Android: text = "About Us" Android: textcolor = "#000000" Android: textsize = "16sp"/> <button Android: Id = "@ + ID/btn_popup_buy" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_margintop = "5dip" Android: layout_weight = "1" Android: Background = "@ drawable/shop_bg" Android: text = "disabled" Android: textcolor = "#000000" Android: textsize = "16sp"/> </linearlayout>
Below are the animation effects of the appearance and exit of popwindow. There are many such things online. Let's take this out. Values/style. xml <? XML version = "1.0" encoding = "UTF-8"?> <Resources> <style name = "popupanimation" parent = "Android: Animation"> <item name = "Android: windowenteranimation "> @ anim/popup_search_show </item> <item name =" Android: export wexitanimation "> @ anim/popup_search_hide </item> </style> </resources> anim/popup_search_show.xml <? XML version = "1.0" encoding = "UTF-8"?> <Set xmlns: Android = "http://schemas.android.com/apk/res/android" Android: interpolator = "@ Android: anim/decelerate_interpolator"> <scale Android: Duration = "500" Android: fromxscale = "1.0" Android: fromyscale = "1.0" Android: effectx = "0.100000024%" Android: effecty = "0.0" Android: toxscale = "0.0" Android: toyscale = "0.0"> </scale> </set>
anim/popup_search_hide.xml<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/decelerate_interpolator" > <scale android:duration="500" android:fromXScale="0.0" android:fromYScale="0.0" android:pivotX="0.100000024%" android:pivotY="0.0" android:toXScale="1.0" android:toYScale="1.0" > </scale></set>