亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android PopupWindow實現(xiàn)左側彈窗效果

 更新時間:2017年10月24日 15:27:18   作者:劉白超  
這篇文章主要為大家詳細介紹了Android PopupWindow實現(xiàn)左側彈窗效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

效果圖:

MainActivity.java頁面核心代碼:

protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);
  //在setContentView之前添加,未添加的話home鍵監(jiān)聽無效,設置窗體屬性
  this.getWindow().setFlags(0x80000000, 0x80000000);
  setContentView(R.layout.activity_main);

  //創(chuàng)建廣播
  //InnerRecevier innerReceiver = new InnerRecevier();
  //動態(tài)注冊廣播
  //IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
  //啟動廣播
  //registerReceiver(innerReceiver, intentFilter);

  //外部網(wǎng)頁
  // 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);
  }
 };
 /*創(chuàng)建PopupWindow*/
 protected void initPopupWindow(){
  //獲取自定義布局文件activity_pop_left.xml 布局文件
  final View popipWindow_view = getLayoutInflater().inflate(R.layout.activity_pop_left,null,false);
  //創(chuàng)建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樣式自定義。

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

相關文章

最新評論