-
popWindow
2014-05-23 18:07:39 -
PopWindow
2018-06-05 12:28:35PopWindow是一种弹窗,像dialog一样是一种悬浮弹窗。 使用: 可以自己定义一个类继承系统里的PopWindow,即自定义,也可以使用系统的PopWIndow。看情况使用吧。 PopWindow和Activity有些地方有点像,比如他可以用...PopWindow是一种弹窗,像dialog一样是一种悬浮弹窗。
使用:
可以自己定义一个类继承系统里的PopWindow,即自定义,也可以使用系统的PopWIndow。看情况使用吧。PopWindow和Activity有些地方有点像,比如他可以用setContentView(View view)来建立自己的内容布局。所以它需要一个xml来定义它自己的布局。
定义popwinodw.xml
代码创建popwindow对象(自己写的类或系统都行)
然后可以给它在代码里 动态设置一些属性
setWidth(ViewGroup.LayoutParams.MATCH_PARENT); //宽 setHeight(ViewGroup.LayoutParams.MATCH_PARENT); // 高 setFocusable(true); // 焦点 setBackgroundDrawable(new ColorDrawable(0x50000000)); // 背景 setAnimationStyle(R.style.PopupAnimation ); //动画 setInputMethodMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); //代码设置弹出键盘是挤压窗口
自定义类里面setContenView(mView); 或者在MainActivity里用对象调用此方法
showAsDropDown(view,0,0,Gravity.CENTER)//展示popwindow
这个方法说一下:
第一个参数,参考view
第二个参数和第三个参数是popwindow左上角坐标:x ,y
第三个参数:设置popwindow位置Gravitydismiss() //用于使popwindow消失
-
popwindow
2019-06-03 09:55:03caidan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { View view1 = LayoutInflater.from(MainActivity.this).inflate(R.layout.popwindow, null); top_re...//菜单点击事件
caidan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
View view1 = LayoutInflater.from(MainActivity.this).inflate(R.layout.popwindow, null);
top_recyclerview = view1.findViewById(R.id.top_recyclerview);
bottom_recyclerview = view1.findViewById(R.id.bottom_recyclerview);
PopupWindow popupWindow = new PopupWindow(view1,LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.showAsDropDown(linear, 9, -10);
RetrofitUtil.getInstance().get(left_url, new RetrofitUtil.CallBack() {
@Override
public void onSuccess(String data) {
Gson gson = new Gson();
final LeftBean leftBean = gson.fromJson(data, LeftBean.class);
//布局管理器
LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(MainActivity.this);
linearLayoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
top_recyclerview.setLayoutManager(linearLayoutManager1);
MyLeftAdapter myLeftAdapter = new MyLeftAdapter(leftBean,MainActivity.this);
top_recyclerview.setAdapter(myLeftAdapter);
myLeftAdapter.onclick(new MyLeftAdapter.ItemClick() {
@Override
public void onClick(int position) {
String id = leftBean.getResult().get(position).getId();
rightPresenter.getShowModel(right_url+"?firstCategoryId="+id);
}
});
}@Override public void onError(String data) { } }); } });
-
Popwindow
2018-10-22 14:55:43package com.example.administrator.popwindow; import android.app.ActionBar; import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; impor...MainActivity:
package com.example.administrator.popwindow; import android.app.ActionBar; import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.Gravity; import android.view.View; import android.view.WindowManager; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private TextView mKuang1,mKuang2,mKuang3; private TextView mXuanxiangyi,mXuanxianger,mXuanxiangsan; private PopupWindow popupWindow; private View popupView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mKuang1=findViewById(R.id.kuang1); mKuang2=findViewById(R.id.kuang2); mKuang3=findViewById(R.id.kuang3); mKuang1.setOnClickListener(this); mKuang2.setOnClickListener(this); mKuang3.setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.kuang1: SortPop(); break; case R.id.kuang2: SortPop(); break; case R.id.kuang3: SortPop(); break; case R.id.xuanxiangyi: Toast.makeText(MainActivity.this,"选项一",Toast.LENGTH_SHORT).show(); break; case R.id.xuanxianger: Toast.makeText(MainActivity.this,"选项二",Toast.LENGTH_SHORT).show(); break; case R.id.xuanxiangsan: Toast.makeText(MainActivity.this,"选项三",Toast.LENGTH_SHORT).show(); break; } } /** * 排序弹出框 */ private void SortPop() { if (popupWindow == null) { popupView = View.inflate(MainActivity.this, R.layout.popwindow, null); mXuanxiangyi = popupView.findViewById(R.id.xuanxiangyi); mXuanxianger = popupView.findViewById(R.id.xuanxianger); mXuanxiangsan = popupView.findViewById(R.id.xuanxiangsan); mXuanxiangyi.setOnClickListener(this); mXuanxianger.setOnClickListener(this); mXuanxiangsan.setOnClickListener(this); // 参数2,3:指明popupwindow的宽度和高度 popupWindow = new PopupWindow(popupView, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT, true); int screenHeigh = getResources().getDisplayMetrics().heightPixels; popupWindow.setHeight(ActionBar.LayoutParams.WRAP_CONTENT); popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { lighton(); } }); popupWindow.setFocusable(true); // 设置点击popupwindow外屏幕其它地方消失 popupWindow.setOutsideTouchable(true); // 在点击之后设置popupwindow的销毁 if (popupWindow.isShowing()) { popupWindow.dismiss(); lighton(); } } // 在点击之后设置popupwindow的销毁 if (popupWindow.isShowing()) { popupWindow.dismiss(); lighton(); } // 设置popupWindow的显示位置,此处是在手机屏幕底部且水平居中的位置 if (Build.VERSION.SDK_INT != 24) { //只有24这个版本有问题,好像是源码的问题 popupWindow.showAsDropDown(mKuang1); } else { //7.0 showAsDropDown没卵子用 得这么写 int[] location = new int[2]; mKuang1.getLocationOnScreen(location); int x = location[0]; int y = location[1]; popupWindow.showAtLocation(mKuang1, Gravity.NO_GRAVITY, 0, y + mKuang1.getHeight()); } } /** * 设置手机屏幕亮度变暗 */ private void lightoff() { WindowManager.LayoutParams lp = this.getWindow().getAttributes(); lp.alpha = 0.3f; this.getWindow().setAttributes(lp); } /** * 设置手机屏幕亮度显示正常 */ private void lighton() { WindowManager.LayoutParams lp = this.getWindow().getAttributes(); lp.alpha = 1f; this.getWindow().setAttributes(lp); } }
MianActivity布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="50dp"> <TextView android:id="@+id/kuang1" android:layout_weight="1" android:layout_width="match_parent" android:text="弹出框1" android:gravity="center" android:layout_height="match_parent" /> <View android:layout_width="1dp" android:background="#f2f2f2" android:layout_height="match_parent"/> <TextView android:id="@+id/kuang2" android:layout_weight="1" android:layout_width="match_parent" android:text="弹出框2" android:gravity="center" android:layout_height="match_parent" /> <View android:layout_width="1dp" android:background="#f2f2f2" android:layout_height="match_parent"/> <TextView android:id="@+id/kuang3" android:layout_weight="1" android:layout_width="match_parent" android:text="弹出框3" android:gravity="center" android:layout_height="match_parent" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#f2f2f2"/> </LinearLayout>
popwindow布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:background="#fff" android:orientation="vertical" android:layout_height="wrap_content"> <TextView android:padding="15dp" android:id="@+id/xuanxiangyi" android:layout_width="match_parent" android:text="选项一" android:layout_height="wrap_content" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#f2f2f2"/> <TextView android:padding="15dp" android:id="@+id/xuanxianger" android:layout_width="match_parent" android:text="选项二" android:layout_height="wrap_content" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#f2f2f2"/> <TextView android:padding="15dp" android:id="@+id/xuanxiangsan" android:layout_width="match_parent" android:text="选项三" android:layout_height="wrap_content" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#f2f2f2"/> </LinearLayout>
下载地址:https://download.csdn.net/download/lanrenxiaowen/10736822
-
POPwindow
2008-06-26 02:32:00{window.open("pop.htm","","width=260,height=316,top=0,scrollbars=0,scrollbars=no");} -
怎么点击popwindow消失popwindow呢
2021-01-10 15:47:03<div><h3>提issue前请务必参考以下格式填写,否则该问题优先级将会降低 ...我需要点击popwindow消失或者点击外部消失 两个都需要</p><p>该提问来源于开源项目:razerdp/BasePopup</p></div>
-
备战2021软考网络规划设计师历年真题套餐
-
马原超级简略复习版(马克思基本原理)
-
整合的PCB封装库 intLib.zip
-
表彰大会实施方案.docx
-
Codeforces Round #695 (Div. 2)
-
微服务系列第七十一季-Spring入门
-
【图像处理】轻松搞懂Canny边缘检测
-
System.out.println(tickets--);
-
选号网网站源码.zip
-
转行做IT-第1章 计算机基础
-
Kotlin协程极简入门与解密
-
西安航空学院软工毕业实训
-
jquery怎么判断radio是否选中
-
最新人教版五年级下册语文第四单元基础过关知识整理.doc
-
做控制要知道的刚体旋转知识旋转矩阵_方向余弦矩阵
-
zynq设计学习笔记2——GPIO之MIO控制LED实验
-
C/C++编程全家桶(Daozy极限编程)
-
最新人教版五年级下册语文第八单元基础过关知识整理.doc
-
eCognition8.9系列产品介绍.pdf
-
23种JAVA设计模式