標籤:android style blog http color 檔案 ar 2014 div
兩布局,一個當前布局頁面和一個點擊展示布局頁面,主程式碼:
public class MainActivity extends Activity { private PopupWindow pop; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); //將layout的xml布局檔案執行個體化為View類對象 LayoutInflater inflater =LayoutInflater.from(this); View view =inflater.inflate(R.layout.mypop, null); //建立PopupWindow,參數為顯示對象,寬,高 final PopupWindow pop =new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); //PopupWindow的設定 pop.setBackgroundDrawable(new BitmapDrawable()); //點擊外邊消失 pop.setOutsideTouchable(true); //設定此參數獲得焦點,否則無法點擊 pop.setFocusable(true); //設定文本監聽事件 TextView text =(TextView) findViewById(R.id.topmenu); text.setOnClickListener(new OnClickListener(){ @Override //判斷是否已經顯示,點擊時如顯示則隱藏,隱藏則顯示 public void onClick(View v) { if(pop.isShowing()){ pop.dismiss(); }else{ pop.showAsDropDown(v); } } });
執行個體下載>>>>>>>>>>>>>>
Android:PopupWindow彈窗