Android PopupWindow實現(xiàn)左側(cè)彈窗效果
本文實例為大家分享了Android PopupWindow實現(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();
//動態(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);
//設(shè)置動畫效果
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è)菜單需單獨設(shè)置一個xml頁面,style樣式自定義。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android開發(fā)之PopupWindow實現(xiàn)彈窗效果
- Android彈窗ListPopupWindow的簡單應(yīng)用詳解
- Android使用 PopupWindow 實現(xiàn)底部彈窗功能
- Android開發(fā)實現(xiàn)popupWindow彈出窗口自定義布局與位置控制方法
- Android Popupwindow彈出窗口的簡單使用方法
- Android編程實現(xiàn)的自定義彈窗(PopupWindow)功能示例
- Android自定義彈出窗口PopupWindow使用技巧
- Android控件PopupWindow模仿ios底部彈窗
- android PopupWindow 和 Activity彈出窗口實現(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-12
Android開發(fā)中Launcher3常見默認配置修改方法總結(jié)
這篇文章主要介紹了Android開發(fā)中Launcher3常見默認配置修改方法,結(jié)合實例形式分析了Android Launcher3的功能與配置修改相關(guān)操作技巧,需要的朋友可以參考下2017-11-11
Android編程實現(xiàn)3D旋轉(zhuǎn)效果實例
這篇文章主要介紹了Android編程實現(xiàn)3D旋轉(zhuǎn)效果的方法,基于Android的Camera類實現(xiàn)坐標變換達到圖片3D旋轉(zhuǎn)效果,需要的朋友可以參考下2016-01-01
Android自定義ViewGroup之WaterfallLayout(二)
這篇文章主要為大家詳細介紹了Android自定義ViewGroup之WaterfallLayout,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
Android程序開發(fā)之ListView實現(xiàn)橫向滾動(帶表頭與固定列)
這篇文章主要介紹了Android程序開發(fā)之ListView實現(xiàn)橫向滾動(帶表頭與固定列)的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07

