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

首頁 > 系統(tǒng) > Android > 正文

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

2020-02-21 17:22:08
字體:
供稿:網(wǎng)友

PopupWindows屬于android.widget的控件之一,它不能直接在布局文件中使用,本文是武林技術頻道小編為大家?guī)淼?a target="_blank">Android PopupWindow實現(xiàn)左側(cè)彈窗效果,希望能幫到大家。

效果圖:

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>

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

以上就是武林技術頻道小編帶給大家的Android PopupWindow實現(xiàn)左側(cè)彈窗效果,希望對大家的學習有所幫助,也希望大家多多支持武林技術頻道。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 高邑县| 喜德县| 台前县| 政和县| 台山市| 改则县| 康马县| 通城县| 西平县| 巢湖市| 鹤庆县| 隆德县| 山阳县| 延庆县| 新竹县| 榆中县| 阜新市| 济源市| 游戏| 屯昌县| 友谊县| 年辖:市辖区| 青田县| 永泰县| 丽江市| 辛集市| 分宜县| 子长县| 德兴市| 北流市| 宾阳县| 鹤峰县| 通化市| 唐海县| 郁南县| 海晏县| 平和县| 贵溪市| 抚州市| 肇源县| 昌平区|