Android:PopupWindow彈窗

來源:互聯網
上載者:User

標籤: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彈窗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.