My Phone管家(19) 應用管理 單獨介紹一下PopupWindow

來源:互聯網
上載者:User

標籤:

My Phone管家(19) 應用管理  單獨介紹一下PopupWindow

在前一節中使用點擊ListView 出現一個快顯視窗, 用來顯示我們的需求。

PopupWindow: A popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.

    PopupWindow 是一個彈出表單, 可以顯示任意的視圖, 他是一個浮動的容器, 顯示在當前activity的上方。

注意要給PopupWindow設定一個背景,否則,會出現點擊back鍵和點擊PopupWindow地區外, PopupWindow不會消失, 

    設定背景:mPopupWindow.setBackgroundDrawable(new ColorDrawable());

(1)按鈕點擊觸發 PopupWindow的顯示, 

  mPopupWindow.showAsDropDown(pView,60,-pView.getHeight());  顯示PopupWindow的位置
  設定popView的彈出效果動畫,

(2) 當點擊PopupWindow地區以外的地方, PopupWindow消失

(3)點擊PopupWindow視圖的選項,執行相應的操作。

 

package com.example.testpopmenu; import android.app.ActionBar.LayoutParams;import android.app.Activity;import android.graphics.drawable.ColorDrawable;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.AnimationSet;import android.view.animation.ScaleAnimation;import android.widget.PopupWindow;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends Activity implements OnClickListener {    PopupWindow mPopupWindow;    View popupView;    AnimationSet animationset;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }    /**     *      * @param v     */    public void Click(View v){        showPopupWindow(v);    }        @Override    public void onClick(View v) {          if(mPopupWindow!= null){            mPopupWindow.dismiss();//消失        }         switch (v.getId()) {        case R.id.tv_lanuch://啟動            Toast.makeText(this, "啟動", Toast.LENGTH_LONG).show();            break;        case R.id.tv_uninstall://卸載            Toast.makeText(this, "系統應用,需要root許可權才可以卸載", Toast.LENGTH_LONG).show();            break;        case R.id.tv_share://分享            Toast.makeText(this, "分享", Toast.LENGTH_LONG).show();           break;        default:            break;        }    }        /**     *快顯視窗      */    protected void showPopupWindow(View pView){        if(mPopupWindow==null){            popupView = View.inflate(this, R.layout.popup_adapter, null);            mPopupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,true);            //設定一個背景,這樣的話點擊返回鍵可用消失            mPopupWindow.setBackgroundDrawable(new ColorDrawable());            TextView tvStart = (TextView) popupView.findViewById(R.id.tv_lanuch);            TextView tvUninstall = (TextView) popupView.findViewById(R.id.tv_uninstall);                TextView tvShare=(TextView) popupView.findViewById(R.id.tv_uninstall);                        tvStart.setOnClickListener(this);            tvUninstall.setOnClickListener(this);            tvShare.setOnClickListener(this);                        //縮放動畫            ScaleAnimation a= new ScaleAnimation(0, 1,0,1,                    Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f                    );            a.setDuration(200);                        //漸層動畫            AlphaAnimation alpha = new AlphaAnimation(0, 1);            alpha.setDuration(200);            animationset = new AnimationSet(false);            animationset.addAnimation(a);            animationset.addAnimation(alpha);                    }        mPopupWindow.showAsDropDown(pView,60,-pView.getHeight());        popupView.startAnimation(animationset);    } }

 

 

My Phone管家(19) 應用管理 單獨介紹一下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.