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

首頁 > 系統 > Android > 正文

Android PopupWindow實現左側彈窗效果

2019-12-12 01:49:14
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Android PopupWindow實現左側彈窗的具體代碼,供大家參考,具體內容如下

效果圖:

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樣式自定義。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇巴县| 根河市| 双牌县| 霞浦县| 日喀则市| 石景山区| 余江县| 绿春县| 石台县| 彝良县| 澄城县| 西和县| 嘉义县| 榆树市| 南丹县| 大洼县| 库尔勒市| 肥乡县| 泸水县| 慈溪市| 永平县| 盈江县| 丰原市| 盐边县| 英山县| 望奎县| 台山市| 镇原县| 尉犁县| 宁都县| 潼南县| 九寨沟县| 乌鲁木齐县| 南昌县| 福清市| 阿坝县| 永靖县| 安西县| 岑巩县| 安西县| 象州县|