popupWindow

@Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        // 彈窗

        // contentView-顯示的View, width, height-寬高
    /*  TextView contentView = new TextView(mContext);
        contentView.setText("彈窗");
        contentView.setTextSize(20);
        contentView.setBackgroundColor(Color.RED);*/
        
        View contentView = View.inflate(mContext, R.layout.pop_window_layout, null);

        final PopupWindow window = new PopupWindow(contentView,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        
        //設(shè)置默認(rèn)只顯示一個(gè)彈窗
        window.setBackgroundDrawable(new ColorDrawable());
        window.setFocusable(true);
        window.setOutsideTouchable(true);//設(shè)置外圍點(diǎn)擊
        
        //設(shè)置動(dòng)畫(huà)樣式
        window.setAnimationStyle(R.style.pop_anim);
        
        //顯示
        //window.showAsDropDown(view);//在哪個(gè)控件下面顯示
        //window.showAsDropDown(view, 80, -60);
        
        AppBean bean = mListDatas.get(position);
        final String packageName = bean.packageName;
        
        //parent是popupWindow要在哪個(gè)夫容器里面展示
        window.showAtLocation(parent, Gravity.CENTER, 0, 0);//顯示在指定位置
        
        TextView tvUninstall = (TextView) contentView.findViewById(R.id.tv_uninstall);
        TextView tvOpen = (TextView) contentView.findViewById(R.id.tv_open);
        TextView tvShare = (TextView) contentView.findViewById(R.id.tv_share);
        TextView tvInfo = (TextView) contentView.findViewById(R.id.tv_info);
        
        
        
        //判斷顯示或者隱藏
        tvUninstall.setVisibility(bean.isSystem ? View.GONE : View.VISIBLE);
        
        PackageManager pkgMgr = getPackageManager();
        final Intent intent = pkgMgr.getLaunchIntentForPackage(packageName);
        tvOpen.setVisibility(intent == null ? View.GONE : View.VISIBLE);
        
        
        tvUninstall.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                //實(shí)現(xiàn)卸載功能
                  /* <intent-filter>
                    <action android:name="android.intent.action.VIEW" />
                    <action android:name="android.intent.action.DELETE" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <data android:scheme="package" />
                </intent-filter>*/
                
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                intent.setAction("android.intent.action.DELETE");
                intent.addCategory("android.intent.category.DEFAULT");
                intent.setData(Uri.parse("package:" + packageName));
                startActivity(intent);
                //startActivityForResult(intent, requestCode)不能實(shí)現(xiàn)監(jiān)聽(tīng)卸載完成
                
                window.dismiss();
            }
        });

window.dismiss();

public class AppBean {
    public Drawable icon;//圖標(biāo) 
    public String name;
    public boolean isInstallSD;//是否安裝在SD卡
    public String space;//應(yīng)用大小
    public boolean isSystem;//是否為系統(tǒng)應(yīng)用
    public String packageName;
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/pop_bg"
    android:orientation="horizontal"
    android:padding="12dp" >

    <TextView
        android:id="@+id/tv_uninstall"
        style="@style/TextNormal"
        android:drawablePadding="4dp"
        android:drawableTop="@drawable/ic_uninstall"
        android:text="卸載" />

    <TextView
        android:id="@+id/tv_open"
        style="@style/TextNormal"
        android:layout_marginLeft="4dp"
        android:drawablePadding="4dp"
        android:drawableTop="@drawable/ic_open"
        android:text="打開(kāi)" />

    <TextView
        android:id="@+id/tv_share"
        style="@style/TextNormal"
        android:layout_marginLeft="4dp"
        android:drawablePadding="4dp"
        android:drawableTop="@drawable/ic_share"
        android:text="分享" />

    <TextView
        android:id="@+id/tv_info"
        style="@style/TextNormal"
        android:layout_marginLeft="4dp"
        android:drawablePadding="4dp"
        android:drawableTop="@drawable/ic_info"
        android:text="信息" />

</LinearLayout>

<style name="pop_anim" parent="@android:style/Animation.Dialog">
        <item name="android:windowEnterAnimation">@anim/pop_enter</item>
        <item name="android:windowExitAnimation">@anim/pop_exit</item>
    </style>

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@interpolator/overshoot" >

    <translate
        android:duration="250"
        android:fromXDelta="100%"
        android:toXDelta="0" />

</set>

<!-- Animation for when a dock window at the bottom of the screen is entering. -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@interpolator/anticipate" >

        <translate
        android:duration="250"
        android:fromXDelta="0"
        android:toXDelta="100%" />

</set>

TWO

LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflater.inflate(R.layout.pop_login, null);
//        View v = View.inflate(getContext(),R.layout.pop_login, null);


        popupWindow = new PopupWindow(v, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        popupWindow.setFocusable(true);
        popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popupWindow.setOutsideTouchable(true);
        //設(shè)置漸入、漸出動(dòng)畫(huà)效果
        popupWindow.setAnimationStyle(android.R.style.Animation_Toast);
        popupWindow.setTouchable(true);
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(true);
        popupWindow.setTouchInterceptor(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                    popupWindow.dismiss();
                    return true;
                }
                return false;
            }
        });

   // popupWindow.update();
        popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
//        popupWindow.showAsDropDown(view,100,-150);

點(diǎn)擊事件中的view就是父容器

public void onViewClicked(View view) {
    switch (view.getId()) {
case R.id.rl_touxiang_personalCenter:
    showPopWindow(view);
    break;
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末炫狱,一起剝皮案震驚了整個(gè)濱河市货矮,隨后出現(xiàn)的幾起案子夷野,更是在濱河造成了極大的恐慌岂昭,老刑警劉巖送矩,帶你破解...
    沈念sama閱讀 217,084評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件登颓,死亡現(xiàn)場(chǎng)離奇詭異名段,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)发框,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,623評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén)躺彬,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人,你說(shuō)我怎么就攤上這事宪拥》乱埃” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 163,450評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵江解,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我徙歼,道長(zhǎng)犁河,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,322評(píng)論 1 293
  • 正文 為了忘掉前任魄梯,我火速辦了婚禮桨螺,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘酿秸。我一直安慰自己灭翔,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,370評(píng)論 6 390
  • 文/花漫 我一把揭開(kāi)白布辣苏。 她就那樣靜靜地躺著肝箱,像睡著了一般。 火紅的嫁衣襯著肌膚如雪稀蟋。 梳的紋絲不亂的頭發(fā)上煌张,一...
    開(kāi)封第一講書(shū)人閱讀 51,274評(píng)論 1 300
  • 那天,我揣著相機(jī)與錄音退客,去河邊找鬼骏融。 笑死,一個(gè)胖子當(dāng)著我的面吹牛萌狂,可吹牛的內(nèi)容都是我干的档玻。 我是一名探鬼主播,決...
    沈念sama閱讀 40,126評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼茫藏,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了务傲?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,980評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤树灶,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后天通,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體泊窘,經(jīng)...
    沈念sama閱讀 45,414評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,599評(píng)論 3 334
  • 正文 我和宋清朗相戀三年烘豹,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了瓜贾。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片携悯。...
    茶點(diǎn)故事閱讀 39,773評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡祭芦,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出憔鬼,到底是詐尸還是另有隱情龟劲,我是刑警寧澤,帶...
    沈念sama閱讀 35,470評(píng)論 5 344
  • 正文 年R本政府宣布昌跌,位于F島的核電站照雁,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏饺蚊。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,080評(píng)論 3 327
  • 文/蒙蒙 一污呼、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧曙求,春花似錦、人聲如沸悟狱。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,713評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)浴麻。三九已至得问,卻和暖如春软免,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背膏萧。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,852評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工蝌衔, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留蝌蹂,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,865評(píng)論 2 370
  • 正文 我出身青樓孤个,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親齐鲤。 傳聞我的和親對(duì)象是個(gè)殘疾皇子斥废,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,689評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容