List<Popup> popupList=new ArrayList<>();//Popup是一個類,中存放的是img的圖片,和一個String類型的文字 Popup popup1=new Popup("天氣",R.drawable.tianqitupian); Popup popup2=new Popup("離線",R.drawable.lixiantupian); Popup popup3=new Popup("夜間",R.drawable.yejiantupian); Popup popup4=new Popup("搜索",R.drawable.sousuotupian); Popup popup5=new Popup("掃一掃",R.drawable.saoyisaotupian); Popup popup6=new Popup("設置",R.drawable.shezhitupian); popupList.add(popup1); popupList.add(popup2); popupList.add(popup3); popupList.add(popup4); popupList.add(popup5); popupList.add(popup6); popupView = MainActivity.this.getLayoutInflater().inflate(R.layout.popupwindow, null);//寫一個popupwindow中爲listView popup_lv = popupView.findViewById(R.id.popup_lv); PopupAdapter popupAdapter=new PopupAdapter(MainActivity.this,popupList); popup_lv.setAdapter(popupAdapter); popup_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {//執行對應的操作 @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if(i==0){ Toast.makeText(MainActivity.this, "0", Toast.LENGTH_SHORT).show(); } if(i==1){ Intent intent = new Intent(MainActivity.this,LixianActivity.class); startActivity(intent); Toast.makeText(MainActivity.this, "1", Toast.LENGTH_SHORT).show(); } if(i==2){ int uiMode;//夜間模式 uiMode = getResources().getConfiguration().uiMode& Configuration.UI_MODE_NIGHT_MASK; if(uiMode == Configuration.UI_MODE_NIGHT_YES){ getDelegate().setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); getSharedPreferences("theme",MODE_PRIVATE).edit().putBoolean("night_theme",false).commit(); }else if(uiMode == Configuration.UI_MODE_NIGHT_NO){ getDelegate().setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); getSharedPreferences("theme",MODE_PRIVATE).edit().putBoolean("night_theme", true).commit(); } recreate(); Toast.makeText(MainActivity.this, "2", Toast.LENGTH_SHORT).show(); } if(i==3){ Toast.makeText(MainActivity.this, "3", Toast.LENGTH_SHORT).show(); } if(i==4){ Toast.makeText(MainActivity.this, "4", Toast.LENGTH_SHORT).show(); } if(i==5){ Toast.makeText(MainActivity.this, "5", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(MainActivity.this,ShezhiActivity.class); startActivity(intent); } } }); PopupWindow popupWindow=new PopupWindow(popupView,400,600);//設置大小 popupWindow.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#EEEEEE")));//設置顏色 popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.update(); popupWindow.showAsDropDown(sandian,0,0);//特別重要
PopWindow
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.