欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android簡單實現(xiàn)自定義彈框(PopupWindow)

 更新時間:2017年04月10日 10:05:50   作者:瞳瞳色丶輕煙  
本文主要介紹了Android利用PopupWindow實現(xiàn)自定義彈框的相關知識。具有很好的參考價值。下面跟著小編一起來看下吧

一:一般都是先上效果圖

二:實現(xiàn)步驟:

1.xml布局實現(xiàn)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@drawable/store_bgimg">
 <RelativeLayout
 android:layout_width="fill_parent"
 android:layout_height="214dp"
 android:layout_centerVertical="true"
 android:layout_marginLeft="31dp"
 android:layout_marginRight="31dp"
 android:background="@drawable/tkbjzj">
 <TextView
  android:id="@+id/tetle"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_marginTop="26dp"
  android:text="七天連鎖酒店"
  android:textColor="#262626"
  android:textSize="18dp" />
 <TextView
  android:id="@+id/textdz"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@+id/tetle"
  android:layout_centerHorizontal="true"
  android:layout_marginTop="34dp"
  android:text="你已領取本店7.5折優(yōu)惠券"
  android:textColor="#ea302e" />
 <View
  android:layout_width="match_parent"
  android:layout_height="0.5dp"
  android:layout_above="@+id/lineardb"
  android:background="#e6e6e6" />
 <LinearLayout
  android:id="@+id/lineardb"
  android:layout_width="match_parent"
  android:layout_height="44dp"
  android:layout_alignParentBottom="true">
  <TextView
  android:id="@+id/textwzdl"
  android:layout_width="0dp"
  android:layout_height="fill_parent"
  android:layout_weight="1"
  android:gravity="center"
  android:text="我知道了"
  android:textColor="#262626"
  android:textSize="16dp" />
  <TextView
  android:id="@+id/textckxq"
  android:layout_width="0dp"
  android:layout_height="fill_parent"
  android:layout_weight="1"
  android:background="#f86c6a"
  android:gravity="center"
  android:text="查看詳情"
  android:textColor="#ffffff"
  android:textSize="16dp" />
 </LinearLayout>
 </RelativeLayout>
</RelativeLayout>

2.drawable文件下的轉(zhuǎn)角,然后在布局引用

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
 <!-- 背景顏色 -->
 <solid android:color="#ffffff" />
 <!-- 控制邊界線顏色和大小 -->
 <stroke
 android:width="1dp"
 android:color="#ffffff" />
 <!-- 控制圓角大小 -->
 <corners android:radius="4dp" />
</shape>

3.activity的實現(xiàn)

/**
 * 彈框
 */
private View mPopupHeadViewy;//創(chuàng)建一個view
private PopupWindow mHeadPopupclly;//PopupWindow
private TextView tetle, textdz;//title,打折
private TextView textwzdl, textckxq;//我知道了,查看詳情
@SuppressWarnings("deprecation")
private void popupHeadWindowcll() {
 mPopupHeadViewy = View.inflate(getActivity(), R.layout.tankuang_layout, null);
 tetle = (TextView) mPopupHeadViewy.findViewById(R.id.tetle);
 textdz = (TextView) mPopupHeadViewy.findViewById(R.id.textdz);
 textwzdl = (TextView) mPopupHeadViewy.findViewById(R.id.textwzdl);
 textckxq = (TextView) mPopupHeadViewy.findViewById(R.id.textckxq);
 mHeadPopupclly = new PopupWindow(mPopupHeadViewy, AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT, true);
 // 在PopupWindow里面就加上下面代碼,讓鍵盤彈出時,不會擋住pop窗口。
 mHeadPopupclly.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
 mHeadPopupclly.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
 mHeadPopupclly.setBackgroundDrawable(new BitmapDrawable());
 mHeadPopupclly.setOutsideTouchable(true);
 mHeadPopupclly.showAsDropDown(textviewid, 0, 0);
 textwzdl.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
  mHeadPopupclly.dismiss();
 }
 });
 textckxq.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
  mHeadPopupclly.dismiss();
  Toast.makeText(getActivity(), "查看詳情", Toast.LENGTH_LONG).show();
 }
 });
}

注意:

1、

mHeadPopupclly = new PopupWindow(mPopupHeadViewy, AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT, true);

這句代碼就是控制彈出框是鋪滿屏幕還是自適應

2、

mHeadPopupclly.showAsDropDown(textviewid, 0, 0);

這句話是這個彈框基于哪個控件之下,textviewid是控件名,后面兩個是坐標

這是一個簡單的自定義彈框,大神勿噴,有用的希望頂一下

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關文章

  • Android中的Intent對象完全解析

    Android中的Intent對象完全解析

    這篇文章主要介紹了Android中的Intent對象,深入講解了intent對象傳遞消息的各種用法,需要的朋友可以參考下
    2016-04-04
  • android 仿微信demo——注冊功能實現(xiàn)(移動端)

    android 仿微信demo——注冊功能實現(xiàn)(移動端)

    本篇文章主要介紹了微信小程序-閱讀小程序?qū)嵗╠emo),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,希望能給你們提供幫助
    2021-06-06
  • Android安裝apk文件并適配Android 7.0詳解

    Android安裝apk文件并適配Android 7.0詳解

    這篇文章主要介紹了Android安裝apk文件并適配Android 7.0詳解的相關資料,需要的朋友可以參考下
    2017-05-05
  • Kotlin基礎學習之Deprecated與Suppress注解使用

    Kotlin基礎學習之Deprecated與Suppress注解使用

    這篇文章主要給大家介紹了關于Kotlin基礎學習之Deprecated與Suppress注解使用的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Kotlin具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-08-08
  • Android中微信小程序支付倒計時功能

    Android中微信小程序支付倒計時功能

    大家在使用微信的時候都注意過微信支付倒計時功能,怎么實現(xiàn)的呢?今天小編給大家分享微信小程序支付倒計時功能實現(xiàn)思路詳解,一起看看吧
    2016-12-12
  • Android Jetpack 狠活Lifecycles與LiveData使用詳解

    Android Jetpack 狠活Lifecycles與LiveData使用詳解

    這篇文章主要為大家介紹了Android Jetpack 狠活Lifecycles與LiveData使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-10-10
  • Android發(fā)送短信功能代碼

    Android發(fā)送短信功能代碼

    這篇文章主要介紹了Android發(fā)送短信功能代碼,并附有較為詳盡的代碼說明,有助于讀者更好的理解代碼功能,需要的朋友可以參考下
    2014-09-09
  • Android StepView實現(xiàn)物流進度效果

    Android StepView實現(xiàn)物流進度效果

    這篇文章主要為大家詳細介紹了Android StepView實現(xiàn)物流進度效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android開發(fā)之加載圖片的方法

    Android開發(fā)之加載圖片的方法

    這篇文章主要介紹了Android開發(fā)之加載圖片的方法,涉及Android圖片操作的相關技巧,需要的朋友可以參考下
    2015-05-05
  • Android中Notification的用法匯總

    Android中Notification的用法匯總

    這篇文章主要介紹了Android中Notification的用法匯總的相關資料,需要的朋友可以參考下
    2016-01-01

最新評論