如果您使用的是華為手機(jī),手機(jī)第三方應(yīng)用在鎖屏界面或解鎖后出現(xiàn)廣告推送,若您不想看到廣告界面,可嘗試以下方式關(guān)閉:
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序設(shè)計(jì)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了修文免費(fèi)建站歡迎大家使用!
1.確認(rèn)產(chǎn)生鎖屏廣告的應(yīng)用,再去設(shè)置界面中找到對(duì)應(yīng)的應(yīng)用關(guān)閉通知:
打開設(shè)置,搜索進(jìn)入應(yīng)用管理,找到前面確認(rèn)的應(yīng)用,點(diǎn)擊 通知/通知管理 , 關(guān)閉允許通知。(關(guān)閉通知后可能會(huì)影響軟件正常消息接收,請(qǐng)您謹(jǐn)慎操作)
2.檢查廣告頁(yè)面中是否有設(shè)置按鈕,若有,點(diǎn)擊并選擇鎖屏顯示關(guān)閉。
3.禁止應(yīng)用使用懸浮窗顯示:打開設(shè)置,搜索并進(jìn)入權(quán)限管理,點(diǎn)擊權(quán)限界面打開懸浮窗,關(guān)閉不常用應(yīng)用開關(guān)。
4.如果您不需要使用“產(chǎn)生鎖屏廣告”的應(yīng)用,建議您直接卸載此應(yīng)用即可。
5. 如果以上方法仍無法解決您的問題,建議您提前備份好數(shù)據(jù)(QQ、微信等第三方應(yīng)用需單獨(dú)備份)后恢復(fù)出廠設(shè)置。
xxx耀10上面...底部漏出來了。另外一個(gè)項(xiàng)目也是類似彈窗,但是沒有這個(gè)問題。
然后對(duì)比了下這個(gè)風(fēng)格文件,發(fā)現(xiàn)是 是否懸浮在Activity之上 的問題:
item name="android:windowIsFloating"true/item設(shè)置為true就行了。
不過發(fā)現(xiàn)一個(gè)現(xiàn)象就是當(dāng)鎖屏再打開的時(shí)候顯示就又正常了...也就是在某個(gè)生命周期里面做了一些事情(具體的先不管了哈。記錄下...)
使用風(fēng)格文件的地方:
正在思考自己嘗試封裝彈窗(計(jì)劃包括分享彈窗,更新彈窗,獎(jiǎng)勵(lì)彈窗等,逐步來)。這個(gè)大概是自定義View差不多了再開始嘗試搞....感覺從開始學(xué)習(xí)了好久,才完成了個(gè)人計(jì)劃的一小半....
iOS中系統(tǒng)基礎(chǔ)的彈窗主要有兩種樣式:UIAlertControllerStyleAlert 與 UIAlertControllerStyleActionSheet。
Android中系統(tǒng)基本的彈出樣式有:按鈕positiveButton與negativeButton, setSingleChoiceItems單選框,setMultiChoiceItems多選框以及setProgressStyle進(jìn)度樣式的彈窗。當(dāng)然、吐司(Toast)也算是Android中比較經(jīng)典的彈窗了。
``
}
//監(jiān)聽alert中 輸入框的文字改變
最近項(xiàng)目中接觸到接口回調(diào),以及Android彈窗PopWindow組件的使用,現(xiàn)在利用學(xué)到的知識(shí)自己寫了一個(gè)簡(jiǎn)單的Demo,練習(xí)下在Android下如何運(yùn)用接口回調(diào),來實(shí)現(xiàn)彈窗PopWindow的功能。
1. 定義一個(gè)接口:OnSelectItemListener。定義一個(gè)方法 void selectItem(String name, int type),作為點(diǎn)擊彈窗的每個(gè)Item的回調(diào)接口。
2. 自定義彈窗類:MyPopupWindow,其布局文件為popup_window.xml。當(dāng)在MainActivity調(diào)用其構(gòu)造函數(shù)創(chuàng)建對(duì)象時(shí),同時(shí)執(zhí)行initPopupWindow()函數(shù),給每個(gè)Item設(shè)置監(jiān)聽器,監(jiān)聽點(diǎn)擊Item時(shí),回調(diào)接口函數(shù)selectItem("Pop Window A", POP_WINDOW_ITEM_1),該函數(shù)在MainActivity中實(shí)現(xiàn)。
3. 主Activity: MainActivity。其布局文件為一個(gè)Button和一個(gè)TextView。監(jiān)聽Button,每當(dāng)點(diǎn)擊則彈出PopWindow,呈現(xiàn)三個(gè)Item。調(diào)用MyPopupWindow類中的方法setOnSelectItemListener(OnSelectItemListener listener),傳入OnSelectItemListener 對(duì)象作為參數(shù),同時(shí)實(shí)現(xiàn)回調(diào)接口OnSelectItemListener的方法void selectItem(String name, int type)。
主Activity: MainActivity. Java
[java] view plain copy
packagecom.lambdroid.callbacktest2;
importandroid.app.Activity;
importandroid.content.Context;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.TextView;
importandroid.widget.Toast;
//聯(lián)系接口的回調(diào)以及PopWindow彈窗的簡(jiǎn)單使用
publicclassMainActivityextendsActivity?{
privateMyPopupWindow?myPopupWindow;
privateButton?btn_pop_window;
privateTextView?tv_display;
protectedContext?context;
@Override
protectedvoidonCreate(Bundle?savedInstanceState)?{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context?=this;
btn_pop_window?=?(Button)?findViewById(R.id.btn_pop_window);
tv_display?=?(TextView)?findViewById(R.id.tv_display);
//給Button設(shè)置事件監(jiān)聽:彈出彈窗
btn_pop_window.setOnClickListener(newView.OnClickListener()?{
@Override
publicvoidonClick(View?v)?{
myPopupWindow.show(btn_pop_window);
}
});
myPopupWindow?=newMyPopupWindow(context);
//實(shí)現(xiàn)OnSelectItemListener接口的selectItem方法:對(duì)于彈窗三個(gè)Item的事件監(jiān)聽
myPopupWindow.setOnSelectItemListener(newOnSelectItemListener()?{
@Override
publicvoidselectItem(String?name,inttype)?{
//點(diǎn)擊電站列表,彈出彈框
if(myPopupWindow?!=null?myPopupWindow.isShowing())?{
myPopupWindow.dismiss();
}
tv_display.setText(name);
switch(type){
caseMyPopupWindow.POP_WINDOW_ITEM_1:
Toast.makeText(context,"我是彈窗A,?我的英文名是"+?name,?Toast.LENGTH_SHORT).show();
break;
caseMyPopupWindow.POP_WINDOW_ITEM_2:
Toast.makeText(context,"我是彈窗B,?我的英文名是"+?name,?Toast.LENGTH_SHORT).show();
break;
caseMyPopupWindow.POP_WINDOW_ITEM_3:
Toast.makeText(context,"我是彈窗C,?我的英文名是"+?name,?Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
});
}
}
activity_main.xml
[html] view plain copy
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/btn_pop_window"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="20dp"
android:padding="20dp"
android:text="Pop?Window"
android:textSize="20sp"/
android:id="@+id/tv_display"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Hello?World!"
android:textSize="30sp"/
自定義彈窗類:MyPopupWindow.java
[java] view plain copy
packagecom.lambdroid.callbacktest2;
importandroid.app.ActionBar;
importandroid.content.Context;
importandroid.graphics.drawable.ColorDrawable;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.widget.LinearLayout;
importandroid.widget.PopupWindow;
publicclassMyPopupWindowimplementsView.OnClickListener{
privatePopupWindow?mPopWindow;
privateContext?mContext;
privateLinearLayout?llPop1;
privateLinearLayout?llPop2;
privateLinearLayout?llPop3;
privateintpw_height;
publicstaticfinalintPOP_WINDOW_ITEM_1?=1;
publicstaticfinalintPOP_WINDOW_ITEM_2?=2;
publicstaticfinalintPOP_WINDOW_ITEM_3?=3;
privateOnSelectItemListener?listener;
publicvoidsetOnSelectItemListener(OnSelectItemListener?listener){
this.listener?=?listener;
}
publicMyPopupWindow(Context?context){
mContext?=?context;
initPopupWindow();//初始化彈窗
}
publicvoidinitPopupWindow(){
View?view?=?LayoutInflater.from(mContext).inflate(R.layout.popup_window,null);
mPopWindow?=newPopupWindow(view,?ActionBar.LayoutParams.WRAP_CONTENT,?ActionBar.LayoutParams.WRAP_CONTENT,true);
mPopWindow.setOutsideTouchable(true);
/**?為其設(shè)置背景,使得其內(nèi)外焦點(diǎn)都可以獲得?*/
mPopWindow.setBackgroundDrawable(newColorDrawable());
mPopWindow.setFocusable(true);
pw_height?=?view.getHeight();
llPop1?=?(LinearLayout)?view.findViewById(R.id.ll_pop_1);
llPop1.setOnClickListener(this);
llPop2?=?(LinearLayout)?view.findViewById(R.id.ll_pop_2);
llPop2.setOnClickListener(this);
llPop3?=?(LinearLayout)?view.findViewById(R.id.ll_pop_3);
llPop3.setOnClickListener(this);
}
//監(jiān)聽三個(gè)彈窗的點(diǎn)擊事件
@Override
publicvoidonClick(View?v)?{
switch(v.getId()){
caseR.id.ll_pop_1:
if(listener?!=null)?{
listener.selectItem("Pop?Window?A",?POP_WINDOW_ITEM_1);//回調(diào)接口
}
break;
caseR.id.ll_pop_2:
if(listener?!=null)?{
listener.selectItem("Pop?Window?B",?POP_WINDOW_ITEM_2);
}
break;
caseR.id.ll_pop_3:
if(listener?!=null)?{
listener.selectItem("Pop?Window?C",?POP_WINDOW_ITEM_1);
}
break;
default:
break;
}
}
//顯示彈窗,并設(shè)置彈窗基于標(biāo)題欄的顯示位置
publicvoidshow(View?view)?{
//popupwindow相對(duì)view位置x軸偏移量
View?viewTemp?=?mPopWindow.getContentView();
viewTemp.measure(0,0);
intwidth?=?viewTemp.getMeasuredWidth();
intxOffset?=?(view.getWidth()?-?width)?/2;
mPopWindow.showAsDropDown(view,?xOffset,0);
}
/**
*?退出popupwindow
*/
publicvoiddismiss()?{
if(mPopWindow?!=null?mPopWindow.isShowing())?{
mPopWindow.dismiss();
}
}
/**
*?popupwindow是否正在顯示
*/
publicbooleanisShowing()?{
if(mPopWindow?!=null)?{
returnmPopWindow.isShowing();
}
returnfalse;
}
}
popup_window.xml
[html] view plain copy
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/ll_alarm_type"
android:layout_width="120dp"
android:layout_height="130dp"
android:orientation="vertical"
android:background="@drawable/popupwindow"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:id="@+id/ll_pop_1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="窗口?A"
android:textSize="15sp"
android:textColor="#ffffff"/
android:id="@+id/ll_pop_2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="窗口?B"
android:textSize="15sp"
android:textColor="#ffffff"/
android:id="@+id/ll_pop_3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="窗口?C"
android:textSize="15sp"
android:textColor="#FFFFFF"/
回調(diào)接口:OnSelectItemListener
[java] view plain copy
packagecom.lambdroid.callbacktest2;
publicinterfaceOnSelectItemListener?{
voidselectItem(String?name,inttype);
}
點(diǎn)擊Button,彈出彈窗,顯示三個(gè)Item
點(diǎn)擊第二個(gè)Item,通過回調(diào)函數(shù),來實(shí)現(xiàn)TextView內(nèi)容的修改,以及彈出Toast
總結(jié)
Java回調(diào)情形涉及很多,本文屬于接口的異步回調(diào):當(dāng)不知道何時(shí)會(huì)執(zhí)行接口的回調(diào)函數(shù),(通過接口回調(diào)來對(duì)獲取到的資源的操作)。除此還有線程間的異步回調(diào)(子線程進(jìn)行耗時(shí)操作,操作完畢通知主線程或?qū)?shù)據(jù)傳給主線程處理),以及利用接口回調(diào)來實(shí)現(xiàn)線程間的數(shù)據(jù)通信等等(Android可以利用Handler來實(shí)現(xiàn))。等下次再舉例說明Java回調(diào)函數(shù)的其它情形。
相對(duì)于AlertDialog的使用,PopupWindow的使用也比較簡(jiǎn)單,這里主要介紹的是PopupWindow的基礎(chǔ)使用包括在使用過程中的一些注意事項(xiàng),做個(gè)筆記。
方式一:
方式二:
當(dāng)然,在實(shí)際的開發(fā)過程中我們并不能僅僅滿足于如何簡(jiǎn)單使用,更多的時(shí)候我們需要去考慮兼容性與擴(kuò)展性的問題,所以,在這里,我對(duì)PopupWindow做了一個(gè)簡(jiǎn)單的封裝,如下所示:
創(chuàng)建PopupWindow的管理類,即PopupWindowManager類
新建類來繼承自PopupWindow
最后進(jìn)行調(diào)用:
到這里,popupWindow的簡(jiǎn)單使用就完成了。最后來講一下在使用popupWindow的過程中需要注意的幾點(diǎn)。
(1)必須手動(dòng)給popupWindow設(shè)置寬度和高度,否則popupWindow不顯示。
(2)在手機(jī)系統(tǒng)的API大于24的時(shí)候全屏展示的時(shí)候會(huì)完全填充整個(gè)屏幕,而不是在目標(biāo)View的下方正常顯示。
(3)在有些手機(jī)上面,全屏展示的時(shí)候底部會(huì)留白,其實(shí)是因?yàn)镾tatusBar的高度沒有計(jì)算進(jìn)去,需要我們自己手動(dòng)計(jì)算出去。
(4)當(dāng)我們?cè)O(shè)置了setFocusable為true的時(shí)候,點(diǎn)擊屏幕事件會(huì)交由onTouchListener處理。
項(xiàng)目中 云信IM同一帳號(hào),在多處登錄時(shí),要實(shí)現(xiàn)互踢功能。
在收到被踢通知時(shí),彈窗提示用戶被踢,點(diǎn)擊繼續(xù)跳轉(zhuǎn)到登錄界面,取消則關(guān)閉App
由于不知道用戶會(huì)在哪個(gè)界面操作時(shí)被踢,接受通知的那個(gè)Activity有可能已經(jīng)失去上下文,導(dǎo)致空指針異常!從而無法 Toast 或 彈窗。
能實(shí)現(xiàn) 全局Dialog 就好了!
由于退出App的時(shí)候,要清除之前所有的Activity,其實(shí)就是退出登錄功能。
我采用 集合法 來實(shí)現(xiàn)的退出登錄 ,在BaseActivity中記錄所有打開過的Activity,然后遍歷清除。
然后在 BaseActivity 中調(diào)用 addActivity() ,不在贅述!
如果能獲取到用戶當(dāng)前觀看的界面,然后將上下文傳過去,就可以實(shí)現(xiàn)全局Dialog
當(dāng)前頁(yè)面也就是棧頂Activity,也就是最后添加的那個(gè)Activity。如下:
然后在使用的地方獲取
即:
注意:之所以返回AppCompatActivity,而不是Activity,
是因?yàn)閺棾鯠ialog 需要 supportFragmentManager ,Activity 獲取不到
以上就可以實(shí)現(xiàn)全局Dialog了。
另外,上述Dialog是用DialogFragment寫的,感興趣可閱 《DialogFragment 去除內(nèi)容區(qū)棱角背景(不規(guī)則圓角)》 ,附有工具類及用法。