Android PopupWindow实现左侧弹窗效果
2017-10-24 15:27
656 查看
效果图:
MainActivity.java页面核心代码:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //在setContentView之前添加,未添加的话home键监听无效,设置窗体属性 this.getWindow().setFlags(0x80000000, 0x80000000); setContentView(R.layout.activity_main); //创建广播 //InnerRecevier innerReceiver = new InnerRecevier(); //动态注册广播 //IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); //启动广播 //registerReceiver(innerReceiver, intentFilter); //外部网页 // init(); //pop Button pop = (Button) findViewById(R.id.popButton); pop.setOnClickListener(popClick); } View.OnClickListener popClick = new View.OnClickListener() { @Override public void onClick(View v) { getPopupWindow(); popupWindow.showAtLocation(v, Gravity.LEFT,0,0); } }; /*创建PopupWindow*/ protected void initPopupWindow(){ //获取自定义布局文件activity_pop_left.xml 布局文件 final View popipWindow_view = getLayoutInflater().inflate(R.layout.activity_pop_left,null,false); //创建Popupwindow 实例,200,LayoutParams.MATCH_PARENT 分别是宽高 popupWindow = new PopupWindow(popipWindow_view,300, ViewGroup.LayoutParams.MATCH_PARENT,true); //设置动画效果 popupWindow.setAnimationStyle(R.style.AnimationFade); //点击其他地方消失 popipWindow_view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (popipWindow_view != null && popipWindow_view.isShown()) { popupWindow.dismiss(); popupWindow = null; } return false; } }); popupWindow.setBackgroundDrawable(new ColorDrawable(0)); Button button1 = (Button) popipWindow_view.findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(),"全屏显示",Toast.LENGTH_SHORT).show(); } }); } /*获取PopipWinsow实例*/ private void getPopupWindow(){ if (null!=popupWindow){ popupWindow.dismiss(); return; }else { initPopupWindow(); } }
activity_main.xml页面
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.x.MainActivity" tools:ignore="MergeRootFrame" > <WebView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/webView" /> <Button android:id="@+id/popButton" android:text="点击弹出左菜单" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </FrameLayout>
左侧菜单需单独设置一个xml页面,style样式自定义。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- android PopupWindow 和 Activity弹出窗口实现方式
- android popwindow实现左侧弹出菜单层及PopupWindow主要方法介绍
- Android Animation实战之屏幕底部弹出PopupWindow
- Android编程实现popupwindow弹出后屏幕背景变成半透明效果
- Android入门之PopupWindow用法实例解析
- Android之用PopupWindow实现弹出菜单的方法详解
- android使用PopupWindow实现页面点击顶部弹出下拉菜单
- Android中PopupWindow响应返回键并关闭的2种方法
- Android PopupWindow 点击外面取消实现代码
- Android中自定义PopupWindow实现弹出框并带有动画效果
相关文章推荐
- Android中PopupWindow实现弹窗输入的效果
- Android实现PopupWindow 弹窗效果 可用于提示信息等
- Android实现PopupWindow 弹窗效果 可用于提示信息等
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- android下使用Fragment实现左侧3级菜单+动画效果
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- 使用PopupWindow和Activity两种不同的方式实现弹窗效果
- android 倒计时、有清除功能编辑框、popupwindow、跑马灯效果实现(基于TextView)
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- 【Android UI设计与开发】第14期:顶部标题栏(五)两种方式实现仿微信标题栏弹窗效果
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- 使用PopupWindow和Activity两种不同的方式实现弹窗效果
- 【Android UI设计与开发】第14期:顶部标题栏(五)两种方式实现仿微信标题栏弹窗效果
- [Android实例] popupwindow实现弹出菜单效果
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果