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

首頁 > 系統 > Android > 正文

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

2019-12-12 03:09:12
字體:
來源:轉載
供稿:網友

一:一般都是先上效果圖

二:實現步驟:

1.xml布局實現

<?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折優惠券"  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文件下的轉角,然后在布局引用

<?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的實現

/** * 彈框 */private View mPopupHeadViewy;//創建一個viewprivate PopupWindow mHeadPopupclly;//PopupWindowprivate 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是控件名,后面兩個是坐標

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

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东明县| 宁河县| 肇庆市| 琼结县| 和龙市| 灵川县| 丁青县| 炎陵县| 布拖县| 大安市| 长岭县| 邯郸市| 天峻县| 富川| 定边县| 边坝县| 抚州市| 陈巴尔虎旗| 桂平市| 肥城市| 肇源县| 巢湖市| 共和县| 海宁市| 吉木萨尔县| 祁门县| 禄丰县| 邢台市| 澜沧| 太原市| 金乡县| 泸州市| 沾益县| 商南县| 清苑县| 宣武区| 叶城县| 石狮市| 石棉县| 乌恰县| 瑞丽市|