本文實(shí)例講述了Android開(kāi)發(fā)之PopupWindow創(chuàng)建彈窗、對(duì)話框的方法。分享給大家供大家參考,具體如下:
創(chuàng)新互聯(lián)建站是一家專(zhuān)注于成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)與策劃設(shè)計(jì),陽(yáng)東網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專(zhuān)注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計(jì)領(lǐng)域的專(zhuān)業(yè)建站公司;建站業(yè)務(wù)涵蓋:陽(yáng)東等地區(qū)。陽(yáng)東做網(wǎng)站價(jià)格咨詢:18982081108簡(jiǎn)介:
PopupWindow 可創(chuàng)建類(lèi)似對(duì)話框風(fēng)格的窗口
效果:
使用方法:
使用PopupWindow 創(chuàng)建對(duì)話框風(fēng)格的串口秩序如下兩步即可:
1. PopupWindow 的構(gòu)造器創(chuàng)建PopupWindow對(duì)象
2. PopupWindow 的showAsDropDown()
將其顯示效果設(shè)置為下拉顯示
3. PopupWindow 的showAtLoacation()
方法將PopupWindow()
在指定位置顯示出來(lái)
下拉顯示效果:
具體實(shí)現(xiàn)方法:
public class MainActivity extends Activity { private PopupWindow popupWindow; private View root; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); root = this.getLayoutInflater().inflate(R.layout.cell,null);//add cell.xml above you mainActivity window popupWindow = new PopupWindow(root,560,700);//create a popupWindow object root.findViewById(R.id.button01).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //close the popupWindow popupWindow.dismiss(); } }); } public void send(View source){ //set the location of PopupWindow popupWindow.showAtLocation(findViewById(R.id.send),Gravity.CENTER,20,20);//you can remove this effect //Use DropDown way to display popupWindow.showAsDropDown(root); } }