Android PopupWindow實(shí)現(xiàn)左側(cè)彈窗效果
本文實(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í)有所幫助,也希望大家多多支持腳本之家。
- Android開發(fā)之PopupWindow實(shí)現(xiàn)彈窗效果
- Android彈窗ListPopupWindow的簡(jiǎn)單應(yīng)用詳解
- Android使用 PopupWindow 實(shí)現(xiàn)底部彈窗功能
- Android開發(fā)實(shí)現(xiàn)popupWindow彈出窗口自定義布局與位置控制方法
- Android Popupwindow彈出窗口的簡(jiǎn)單使用方法
- Android編程實(shí)現(xiàn)的自定義彈窗(PopupWindow)功能示例
- Android自定義彈出窗口PopupWindow使用技巧
- Android控件PopupWindow模仿ios底部彈窗
- android PopupWindow 和 Activity彈出窗口實(shí)現(xiàn)方式
- Android中PopupWindow彈出式窗口使用方法詳解
相關(guān)文章
Android 出現(xiàn)問題Installation error: INSTALL_FAILED_CONFLICTING_P
這篇文章主要介紹了Android 出現(xiàn)問題Installation error: INSTALL_FAILED_CONFLICTING_PROVIDER解決辦法的相關(guān)資料,需要的朋友可以參考下2016-12-12Android協(xié)程的7個(gè)重要知識(shí)點(diǎn)匯總
在現(xiàn)代Android應(yīng)用開發(fā)中,協(xié)程(Coroutine)已經(jīng)成為一種不可或缺的技術(shù),它不僅簡(jiǎn)化了異步編程,還提供了許多強(qiáng)大的工具和功能,可以在高階場(chǎng)景中發(fā)揮出色的表現(xiàn),本文將深入探討Coroutine重要知識(shí)點(diǎn),幫助開發(fā)者更好地利用Coroutine來構(gòu)建高效的Android應(yīng)用2023-09-09Android開發(fā)中Launcher3常見默認(rèn)配置修改方法總結(jié)
這篇文章主要介紹了Android開發(fā)中Launcher3常見默認(rèn)配置修改方法,結(jié)合實(shí)例形式分析了Android Launcher3的功能與配置修改相關(guān)操作技巧,需要的朋友可以參考下2017-11-11Android編程實(shí)現(xiàn)3D旋轉(zhuǎn)效果實(shí)例
這篇文章主要介紹了Android編程實(shí)現(xiàn)3D旋轉(zhuǎn)效果的方法,基于Android的Camera類實(shí)現(xiàn)坐標(biāo)變換達(dá)到圖片3D旋轉(zhuǎn)效果,需要的朋友可以參考下2016-01-01Android Build類的詳解及簡(jiǎn)單實(shí)例
這篇文章主要介紹了Android Build類的詳解及簡(jiǎn)單實(shí)例的相關(guān)資料,希望通過本文大家能夠理解掌握這部分內(nèi)容,需要的朋友可以參考下2017-08-08Android實(shí)現(xiàn)倒計(jì)時(shí)的方案梳理
這篇文章主要介紹了Android實(shí)現(xiàn)倒計(jì)時(shí)的方案梳理,下面文章圍繞主題展開Android倒計(jì)時(shí)方案,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08Android自定義ViewGroup之WaterfallLayout(二)
這篇文章主要為大家詳細(xì)介紹了Android自定義ViewGroup之WaterfallLayout,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09Android程序開發(fā)之ListView實(shí)現(xiàn)橫向滾動(dòng)(帶表頭與固定列)
這篇文章主要介紹了Android程序開發(fā)之ListView實(shí)現(xiàn)橫向滾動(dòng)(帶表頭與固定列)的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07