最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Popupwindow 的簡(jiǎn)單實(shí)用案例(顯示在控件下方)

 更新時(shí)間:2017年04月14日 11:37:35   投稿:jingxian  
下面小編就為大家?guī)硪黄狿opupwindow 的簡(jiǎn)單實(shí)用案例(顯示在控件下方)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

第一步:

private PopupWindow mPopupWindow;

第二步:寫一個(gè)popupwindow的布局文件XML

<?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:orientation="vertical">
  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#669E9E9E">
<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:background="#E4E4E4"
  >
  <TextView
    android:id="@+id/popupwindow_Jan"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="一月份"
    android:gravity="center"
    />
  <TextView
    android:id="@+id/popupwindow_Feb"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="二月份"
    android:gravity="center"
    />
  <TextView
    android:id="@+id/popupwindow_Mar"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="三月份"
    android:gravity="center"
    />
</LinearLayout>
  </RelativeLayout>
</LinearLayout>

第三步:在Activity寫代碼

public void onClick(View v) {
  switch (v.getId()) {
   case R.id.home_travel_modes_yuefen_textview:
       showPopupWindow(v);
      break;
   case R.id.popupwindow_Jan:
      showToastMsg("一月份");
      break;
    case R.id.popupwindow_Feb:
      showToastMsg("二月份");
      break;
    default:
      break;
  }

 public void showPopupWindow(View v){
    View contentView = LayoutInflater.from(HomeTravelModesActivity.this).inflate(R.layout.home_popuplayout, null);
    TextView JanText = (TextView)contentView.findViewById(R.id.popupwindow_Jan);
    TextView FebText = (TextView)contentView.findViewById(R.id.popupwindow_Feb);
    TextView MarText = (TextView)contentView.findViewById(R.id.popupwindow_Mar);
    JanText.setOnClickListener(this);
    FebText.setOnClickListener(this);
    MarText.setOnClickListener(this);
    final PopupWindow popupWindow = new PopupWindow(contentView,
        LinearLayout.LayoutParams.MATCH_PARENT, 300, true);
    popupWindow.setTouchable(true);

//    popupWindow.setTouchInterceptor(new View.OnTouchListener() {
//
//      @Override
//      public boolean onTouch(View v, MotionEvent event) {
//
//        Log.i("mengdd", "onTouch : ");
//
//        return false;
//        // 這里如果返回true的話,touch事件將被攔截
//        // 攔截后 PopupWindow的onTouchEvent不被調(diào)用,這樣點(diǎn)擊外部區(qū)域無法dismiss
//      }
//    });
    // 如果不設(shè)置PopupWindow的背景,無論是點(diǎn)擊外部區(qū)域還是Back鍵都無法dismiss彈框
    // 我覺得這里是API的一個(gè)bug
    popupWindow.setBackgroundDrawable(getResources().getDrawable(
        R.mipmap.ic_launcher));
    // 設(shè)置好參數(shù)之后再show
    popupWindow.showAsDropDown(v);
  }

注:

若在Activity的onCreate()方法中直接寫彈出PopupWindow()方法報(bào)錯(cuò),因?yàn)锳ctivity沒有完全啟動(dòng)是不能彈出PopupWindow的,那我們只需要在Activity完全啟動(dòng)后在彈出PopupWindow就行了。

重寫一下onWindowFocusChanged()方法:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
  super.onWindowFocusChanged(hasFocus);
  //彈出PopupWindow的具體代碼
}

以上這篇Popupwindow 的簡(jiǎn)單實(shí)用案例(顯示在控件下方)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

正镶白旗| 青神县| 镇安县| 东乡族自治县| 无极县| 涟源市| 泰顺县| 磴口县| 海口市| 米脂县| 萨嘎县| 聂荣县| 吉隆县| 三穗县| 定襄县| 满洲里市| 彭泽县| 内黄县| 五原县| 吉木萨尔县| 陆川县| 银川市| 利川市| 左贡县| 鄂伦春自治旗| 年辖:市辖区| 襄汾县| 阿拉善左旗| 晋城| 蒲江县| 武隆县| 汝阳县| 乌兰浩特市| 襄樊市| 法库县| 肥西县| 红河县| 许昌市| 玉山县| 莒南县| 岳普湖县|