這篇文章主要講解了Android PhoneWindowManager監(jiān)聽(tīng)屏幕右側(cè)向左滑動(dòng)實(shí)現(xiàn)返回功能的實(shí)現(xiàn),內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。
成都創(chuàng)新互聯(lián)公司主營(yíng)企業(yè)營(yíng)銷(xiāo)型網(wǎng)站建設(shè),為眾多企業(yè)提供了成都品牌網(wǎng)站建設(shè)服務(wù),建網(wǎng)站哪家好?擁有多年的成都營(yíng)銷(xiāo)網(wǎng)站建設(shè)流程,能夠?yàn)槠髽I(yè)定制化制作網(wǎng)站服務(wù),在公司網(wǎng)站建設(shè)維護(hù)方面成績(jī)突出。
由于項(xiàng)目沒(méi)有設(shè)計(jì)返回鍵,一旦進(jìn)入別的應(yīng)用,就無(wú)法回到桌面。只能通過(guò)串口輸入input keyevent 4(返回鍵)來(lái)返回桌面,為了方便調(diào)試,在Framework 中監(jiān)聽(tīng)手勢(shì),實(shí)現(xiàn)返回功能。
在frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager中有這么一段代碼
mSystemGestures = new SystemGesturesPointerEventListener(context, new SystemGesturesPointerEventListener.Callbacks() { @Override public void onSwipeFromTop() { Log.i("gyx","onSwipeFromTop"); if (mStatusBar != null) { requestTransientBars(mStatusBar); } } @Override public void onSwipeFromBottom() { Log.i("gyx","onSwipeFromBottom"); if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) { requestTransientBars(mNavigationBar); } } @Override public void onSwipeFromRight() { Log.i("gyx","onSwipeFromRight"); sendKeyCode(4); Log.i("gyx","sendKeyCode 4"); if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_RIGHT) { requestTransientBars(mNavigationBar); } } @Override public void onSwipeFromLeft() { Log.i("gyx","onSwipeFromLeft"); if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_LEFT) { requestTransientBars(mNavigationBar); } } @Override public void onFling(int duration) { if (mPowerManagerInternal != null) { mPowerManagerInternal.powerHint( PowerHint.INTERACTION, duration); } } @Override public void onDebug() { // no-op } @Override public void onDown() { mOrientationListener.onTouchStart(); } @Override public void onUpOrCancel() { mOrientationListener.onTouchEnd(); } @Override public void onMouseHoverAtTop() { mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS; mHandler.sendMessageDelayed(msg, 500); } @Override public void onMouseHoverAtBottom() { mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION; mHandler.sendMessageDelayed(msg, 500); } @Override public void onMouseLeaveFromEdge() { mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); } });
代碼中監(jiān)聽(tīng)了手勢(shì)操作,其中onSwipeFromRight()
就是當(dāng)從屏幕的右側(cè)向左滑動(dòng)時(shí)會(huì)觸發(fā),只要在這里加入返回的功能即可;
實(shí)現(xiàn)返回按鍵的功能代碼如下
private void sendKeyCode(final int keyCode) { new Thread(new Runnable() { @Override public void run() { try { // 創(chuàng)建一個(gè)Instrumentation對(duì)象 Instrumentation inst = new Instrumentation(); // 調(diào)用inst對(duì)象的按鍵模擬方法 inst.sendKeyDownUpSync(keyCode); } catch (Exception e) { e.printStackTrace(); } } }).start(); }
看完上述內(nèi)容,是不是對(duì)Android PhoneWindowManager監(jiān)聽(tīng)屏幕右側(cè)向左滑動(dòng)實(shí)現(xiàn)返回功能的實(shí)現(xiàn)有進(jìn)一步的了解,如果還想學(xué)習(xí)更多內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當(dāng)前名稱(chēng):AndroidPhoneWindowManager監(jiān)聽(tīng)屏幕右側(cè)向左滑動(dòng)實(shí)現(xiàn)返回功能的實(shí)現(xiàn)
網(wǎng)站網(wǎng)址:http://vcdvsql.cn/article48/pdedhp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、網(wǎng)站排名、小程序開(kāi)發(fā)、網(wǎng)站設(shè)計(jì)公司、商城網(wǎng)站、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)