欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

iOS實(shí)現(xiàn)底部彈出PopupWindow效果iOS改變背景透明效果

底部彈出PopupWindow,背景變?yōu)榘胪该餍Ч捎脙煞N方式實(shí)現(xiàn)

創(chuàng)新互聯(lián)專(zhuān)注為客戶(hù)提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、獨(dú)山子網(wǎng)絡(luò)推廣、微信平臺(tái)小程序開(kāi)發(fā)、獨(dú)山子網(wǎng)絡(luò)營(yíng)銷(xiāo)、獨(dú)山子企業(yè)策劃、獨(dú)山子品牌公關(guān)、搜索引擎seo、人物專(zhuān)訪(fǎng)、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供獨(dú)山子建站搭建服務(wù),24小時(shí)服務(wù)熱線(xiàn):18982081108,官方網(wǎng)址:aaarwkj.com

先來(lái)看看運(yùn)行效果圖

iOS實(shí)現(xiàn)底部彈出PopupWindow效果 iOS改變背景透明效果
iOS實(shí)現(xiàn)底部彈出PopupWindow效果 iOS改變背景透明效果

[方式一]實(shí)現(xiàn)從底部彈出PopupWindow

原理:定義一個(gè)高度為wrap_content的PopupWindow布局文件,根據(jù)屏幕底部的位置顯示在Bottom

1.首先定義一個(gè)高度為wrap_content的PopupWindow布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center"
  android:padding="8dp"
  android:orientation="vertical" >

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical"
    android:background="@drawable/shape_info_bg">
    <TextView android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="8dp"
      android:gravity="center"
      android:textColor="@color/theme_blue"
      android:text="拍照"/>
    <View android:layout_width="match_parent" 
      android:layout_height="0.2dp"
      android:background="@color/theme_blue"/>
    <TextView android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="8dp"
      android:gravity="center"
      android:textColor="@color/theme_blue"
      android:text="相冊(cè)"/>
  </LinearLayout>

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:padding="1dp">
    <Button
      android:id="@+id/btn_cancle"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:padding="8dp"
      android:textColor="@color/theme_blue"
      android:background="@drawable/shape_info_bg"
      android:text="取消" />
  </RelativeLayout>
</LinearLayout>

2.在PopupWindow所在的Activity根布局中聲明id(在彈出PopupWindow作為位置參考的相對(duì)View)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/root_main"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" 
  android:background="@color/white">

  <Button android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="底部彈出PopupWindow"
    android:onClick="openPop"/>

   <Button android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="半透明底部PopupWindow"
    android:onClick="openPop2"/>
</LinearLayout>

3.MainActivity中點(diǎn)擊按鈕彈出PopupWindow

/** 彈出底部對(duì)話(huà)框 */
public void openPop(View view) {
  View popView = LayoutInflater.from(mContext).inflate(
      R.layout.pop_bottom, null);
  View rootView = findViewById(R.id.root_main); // 當(dāng)前頁(yè)面的根佈局
  final PopupWindow popupWindow = new PopupWindow(popView,    LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);

  setBackgroundAlpha(0.5f);//設(shè)置屏幕透明度

  popupWindow.setBackgroundDrawable(new BitmapDrawable());
  popupWindow.setFocusable(true);// 點(diǎn)擊空白處時(shí),隱藏掉pop窗口
  // 顯示在根佈局的底部
  popupWindow.showAtLocation(rootView, Gravity.BOTTOM | Gravity.LEFT, 0,
      0);

}

4.設(shè)置背景變?yōu)榘胪该餍Ч?,由于PopupWindow中并未設(shè)置背景色,所以彈出時(shí)PopupWindow以外的部分顯示當(dāng)前Acitivity的內(nèi)容,設(shè)置背景色原理通過(guò)設(shè)置當(dāng)前Activity所在屏幕的透明度來(lái)達(dá)到背景透明的效果!在退出時(shí)popupWindow時(shí),需要恢復(fù)屏幕原有透明度

popupWindow.setOnDismissListener(new OnDismissListener() {
      @Override
      public void onDismiss() {
        // popupWindow隱藏時(shí)恢復(fù)屏幕正常透明度
        setBackgroundAlpha(1.0f);
      }
    });
/**
 * 設(shè)置添加屏幕的背景透明度
 * 
 * @param bgAlpha
 *      屏幕透明度0.0-1.0 1表示完全不透明
 */
public void setBackgroundAlpha(float bgAlpha) {
  WindowManager.LayoutParams lp = ((Activity) mContext).getWindow()
      .getAttributes();
  lp.alpha = bgAlpha;
  ((Activity) mContext).getWindow().setAttributes(lp);
}

[方式二]全屏PopupWindow實(shí)現(xiàn)底部彈出,背景半透明

原理:彈出一個(gè)全屏popupWindow,高度為match_parent,將根布局的Gravity屬性設(shè)置bottom,根布局背景設(shè)置為一個(gè)半透明的顏色#36000000, 彈出時(shí)全屏的popupWindow半透明效果背景覆蓋了在Activity之上 給人感覺(jué)上是popupWindow彈出后,背景變成半透明

布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:padding="8dp"
  android:orientation="vertical" 
  android:background="#36000000"
  android:gravity="bottom">

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical"
    android:background="@drawable/shape_info_bg">
    <TextView android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="8dp"
      android:gravity="center"
      android:textColor="@color/theme_blue"
      android:text="拍照"/>
    <View android:layout_width="match_parent" 
      android:layout_height="0.2dp"
      android:background="@color/theme_blue"/>
    <TextView android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="8dp"
      android:gravity="center"
      android:textColor="@color/theme_blue"
      android:text="相冊(cè)"/>
  </LinearLayout>

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:padding="1dp">
    <Button
      android:id="@+id/btn_cancle"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:padding="8dp"
      android:textColor="@color/theme_blue"
      android:background="@drawable/shape_info_bg"
      android:text="取消" />
  </RelativeLayout>
</LinearLayout>

彈出方法和方式一相似,不過(guò)不用再監(jiān)聽(tīng)popupWindow的退出事件

/**
 * 彈出底部對(duì)話(huà)框,達(dá)到背景背景透明效果
 * 
 * 實(shí)現(xiàn)原理:彈出一個(gè)全屏popupWindow,將Gravity屬性設(shè)置bottom,根背景設(shè)置為一個(gè)半透明的顏色,
 * 彈出時(shí)popupWindow的半透明效果背景覆蓋了在Activity之上 給人感覺(jué)上是popupWindow彈出后,背景變成半透明
 */
public void openPop2(View view) {
  View popView = LayoutInflater.from(mContext).inflate(
      R.layout.pop_bottom_alpha, null);
  View rootView = findViewById(R.id.root_main); // 當(dāng)前頁(yè)面的根佈局
  final PopupWindow popupWindow = new PopupWindow(popView,
      LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

  // 設(shè)置彈出動(dòng)畫(huà)
  popupWindow.setAnimationStyle(R.style.AnimationFadeBottom);
  popupWindow.setBackgroundDrawable(new BitmapDrawable());
  // 顯示在根佈局的底部
  popupWindow.showAtLocation(rootView, Gravity.BOTTOM | Gravity.LEFT, 0,
      0);
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

網(wǎng)站名稱(chēng):iOS實(shí)現(xiàn)底部彈出PopupWindow效果iOS改變背景透明效果
當(dāng)前網(wǎng)址:http://aaarwkj.com/article2/gpgeic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃品牌網(wǎng)站制作、面包屑導(dǎo)航自適應(yīng)網(wǎng)站、關(guān)鍵詞優(yōu)化、電子商務(wù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)
国产在线精品91国自产拍| 欧美一日韩一级片免费看| 亚洲欧美日韩不卡视频| 男人av天堂手机在线| 日本电影在线看一区二区| 国产剧免费看视频网站成人| 久久精品久久久精品| 亚洲精品一区二区三区色| 国产黄色一区二区三区四区| 欧美日韩另类国产综合| 国产成人精品一区二区国产乱码| 国产亚洲中文久久网久久| 中文字幕人妻久久精品一区| 亚洲国产视频中文字幕| 一区二区不卡中文av| 手机在线观看午夜小视频| 国产精品成人av在线网站| 人人爽久久爱夜夜躁一区| 亚洲天堂岛av一区二区| 亚洲综合国产一区二区| 中文字幕熟妇人妻av在线| 热久久这里只有精品视频| 欧美一区二区国产日韩在线| 亚洲狠狠爱一区二区三区| 精品人妻一区三区蜜桃| 久久久久精品国产亚洲av影院| 欧美精品一区二区网址| 欧美中文日韩国产字幕| 综合激情网激情五月天| 加勒比视频在线观看一区| 色噜噜色一区二区三区| 成人午夜激情在线观看| av天堂高清在线观看| 青青草免费在线视频蜜臀| 日韩精品人妻一区二区网站| 日本人妻伦理在线播放| 综合国产精品久久久久久| 中文字幕亚洲入口久久| 另类激情综合在线观看| 天天干夜夜操操操操| 日本加勒比一本在线观看|