国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現簡單的popupwindow提示框

2019-10-21 21:36:54
字體:
來源:轉載
供稿:網友

Popupwindow大家肯定都特別熟悉了 像一般的提示框的話我們會用Dialog來做 但是隨著設計要求的不斷提高,App中各式各樣的提示框都有,很明顯普通的Dialog實現起來就比較吃力了 所以用Popupwindow來實現是最好不過了 ,于是我也自己寫了一個popupwindow彈出的一個方法,代碼量少簡單靈活 先看一下效果圖

Android,popupwindow,提示框

大致效果就是這樣 當然你也可以將layout中的布局換成自己的布局 接下來是代碼

private void ejectPopup() {     View parent = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);    View popView = View.inflate(this, R.layout.details_share, null);      int width = getResources().getDisplayMetrics().widthPixels;    int height = getResources().getDisplayMetrics().heightPixels;//    int i = height /5*2;     popWindow = new PopupWindow(popView, width, ViewGroup.LayoutParams.WRAP_CONTENT);    popWindow.setAnimationStyle(R.style.Search_PopupWindowAnimation);    popWindow.setFocusable(true);    popWindow.setOutsideTouchable(false);// 設置同意在外點擊消失    ColorDrawable dw = new ColorDrawable(0x30000000);    popWindow.setBackgroundDrawable(dw);    popWindow.showAtLocation(parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);    popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//被home鍵擋住    //給popup中的按鈕做監聽    WindowManager.LayoutParams lp = getWindow().getAttributes();    lp.alpha = (float) 0.7; //0.0-1.0    getWindow().setAttributes(lp);    popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {      @Override      public void onDismiss() {        WindowManager.LayoutParams lp = getWindow().getAttributes();        lp.alpha = (float) 1; //0.0-1.0        getWindow().setAttributes(lp);      }    });}

這個就是調用的方法  背景變暗可以通過這段代碼來實現

 popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {      @Override      public void onDismiss() {        WindowManager.LayoutParams lp = getWindow().getAttributes();        lp.alpha = (float) 1; //0.0-1.0        getWindow().setAttributes(lp);      }    });

當讓也可以讓ui妹子給你切一個透明的背景圖片 
最后是layout中的代碼

<?xml version="1.0" encoding="utf-8"?><com.zhy.autolayout.AutoLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:app="http://schemas.android.com/apk/res-auto"  android:orientation="vertical" android:layout_width="match_parent"  android:background="#fff"  android:layout_height="239dp">   <com.zhy.autolayout.AutoLinearLayout    android:gravity="center"    android:layout_width="match_parent"    android:layout_height="51dp">     <TextView      android:text="請選擇分享平臺"      android:textColor="#29292a"      android:textSize="18sp"      android:layout_width="wrap_content"      android:layout_height="wrap_content" />  </com.zhy.autolayout.AutoLinearLayout>   <TextView    android:background="@color/divider_color"    android:layout_width="match_parent"    android:layout_height="1dp" />    <com.zhy.autolayout.AutoLinearLayout    android:layout_marginBottom="10dp"    android:layout_width="match_parent"    android:layout_height="132dp">    <com.zhy.autolayout.AutoRelativeLayout      android:id="@+id/share_WX"      android:layout_marginLeft="13dp"      android:layout_width="0dp"      android:layout_weight="1"      android:layout_height="match_parent">       <ImageView        android:id="@+id/share_WX_icon"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        app:srcCompat="@drawable/wechat" />       <TextView        android:text="微信"        android:layout_marginTop="6dp"        android:layout_below="@id/share_WX_icon"        android:layout_centerHorizontal="true"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    </com.zhy.autolayout.AutoRelativeLayout>    <com.zhy.autolayout.AutoRelativeLayout      android:id="@+id/share_WXPYQ"      android:layout_width="0dp"      android:layout_weight="1"      android:layout_height="match_parent">       <ImageView        android:id="@+id/share_WXPYQ_icon"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        app:srcCompat="@drawable/circleoffriends" />       <TextView        android:text="朋友圈"        android:layout_marginTop="6dp"        android:layout_below="@id/share_WXPYQ_icon"        android:layout_centerHorizontal="true"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    </com.zhy.autolayout.AutoRelativeLayout>    <com.zhy.autolayout.AutoRelativeLayout      android:layout_width="0dp"      android:id="@+id/share_QQ"      android:layout_weight="1"      android:layout_height="match_parent">       <ImageView        android:id="@+id/share_QQ_icon"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        app:srcCompat="@drawable/qq" />       <TextView        android:text="QQ"        android:layout_marginTop="6dp"        android:layout_below="@id/share_QQ_icon"        android:layout_centerHorizontal="true"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    </com.zhy.autolayout.AutoRelativeLayout>    <com.zhy.autolayout.AutoRelativeLayout      android:layout_width="0dp"      android:layout_weight="1"      android:id="@+id/share_QQKJ"      android:layout_height="match_parent">       <ImageView        android:id="@+id/share_QQKJ_icon"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        app:srcCompat="@drawable/zone" />       <TextView        android:text="空間"        android:layout_marginTop="6dp"        android:layout_below="@id/share_QQKJ_icon"        android:layout_centerHorizontal="true"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    </com.zhy.autolayout.AutoRelativeLayout>     <com.zhy.autolayout.AutoRelativeLayout      android:id="@+id/share_WB"      android:layout_width="0dp"      android:layout_height="match_parent"      android:layout_marginRight="13dp"      android:layout_weight="1">       <ImageView        android:id="@+id/share_WB_icon"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        app:srcCompat="@drawable/weibo" />       <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/share_WB_icon"        android:layout_centerHorizontal="true"        android:layout_marginTop="6dp"        android:text="微博" />    </com.zhy.autolayout.AutoRelativeLayout>   </com.zhy.autolayout.AutoLinearLayout>  <TextView    android:background="@color/divider_color"    android:layout_width="match_parent"    android:layout_height="1dp" />  <com.zhy.autolayout.AutoLinearLayout    android:id="@+id/share_cancel"    android:gravity="center"    android:layout_width="match_parent"    android:layout_height="50dp">    <TextView      android:gravity="center"      android:textSize="15sp"      android:textColor="#2d2d2d"      android:text="取消"      android:layout_width="wrap_content"      android:layout_height="match_parent" />  </com.zhy.autolayout.AutoLinearLayout></com.zhy.autolayout.AutoLinearLayout>

ok  沒了

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大石桥市| 光山县| 金溪县| 冷水江市| 盐城市| 三江| 北安市| 商城县| 石景山区| 沙雅县| 临海市| 永年县| 珲春市| 固始县| 鹤壁市| 宁远县| 东安县| 垣曲县| 三都| 綦江县| 东安县| 五大连池市| 南投县| 永济市| 神木县| 绵竹市| 陈巴尔虎旗| 崇仁县| 深水埗区| 鹤山市| 邛崃市| 莆田市| 麻阳| 大理市| 腾冲县| 长垣县| 沛县| 肃宁县| 盐边县| 图木舒克市| 霞浦县|