欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android PopupWindow實(shí)現(xiàn)左側(cè)彈窗效果

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

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

效果圖:

MainActivity.java頁面核心代碼:

protected void onCreate(Bundle savedInstanceState) {

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

  //創(chuàng)建廣播
  //InnerRecevier innerReceiver = new InnerRecevier();
  //動(dòng)態(tài)注冊(cè)廣播
  //IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
  //啟動(dòng)廣播
  //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 實(shí)例,200,LayoutParams.MATCH_PARENT 分別是寬高
  popupWindow = new PopupWindow(popipWindow_view,300, ViewGroup.LayoutParams.MATCH_PARENT,true);
//設(shè)置動(dòng)畫效果
  popupWindow.setAnimationStyle(R.style.AnimationFade);
  //點(diǎn)擊其他地方消失
  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實(shí)例*/

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="點(diǎn)擊彈出左菜單" android:layout_width="fill_parent"
  android:layout_height="wrap_content" />
</FrameLayout>

左側(cè)菜單需單獨(dú)設(shè)置一個(gè)xml頁面,style樣式自定義。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論