日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > 如何Android中自定義Navigationbar

如何Android中自定義Navigationbar

來源:程序員人生   發布時間:2015-03-16 10:42:18 閱讀次數:7174次

如何控制android系統中NavigationBar 的顯示與隱藏文章里扼要地介紹了Navigationbar的背景知識,

NavigationBar的代碼是放在...frameworksasepackagesSystemUI路徑下面的。該路徑下的工程主要負責手機中系統級UI的顯示部份,以下圖框當選中部份(包括其中的通知欄的顯示),USB的連接,截屏等等。


NavigationBar的創建

navigationbar 的代碼是在SystemUI工程SystemUI/src/com/android/systemui/statusbar/phone的路徑下,其中navigationbar是由PhoneStatusBar.java類創建的。在該類的makeStatusBarView()方法下,可以看到創建Navigationbar的進程:

try { boolean showNav = mWindowManagerService.hasNavigationBar(); /// M: Support Smartbook Feature. if (true) Log.v(TAG, "hasNavigationBar=" + showNav); if (showNav) { mNavigationBarView = (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null); mNavigationBarView.setDisabledFlags(mDisabled); mNavigationBarView.setBar(this); mNavigationBarView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { checkUserAutohide(v, event); return false; }}); } } catch (RemoteException ex) { // no window manager? good luck with that }
WindowManagerService通過判斷是不是需要顯示NavigationBar來決定是不是需要創建NavigationBarView, NavigationBarView即為我們看到視圖的view了,navigation_bar即為NavigationBarView實例化的layout,你可以在SystemUI工程下的layout文件夾下找到。

通過修改navigation_bar布局的方式來自定義NavigationBar的UI。在該layout文件中有這樣1個類。com.android.systemui.statusbar.policy.KeyButtonView,它是系統定義的在NavigationBar上的按鈕類(后面會講到),點擊會產生波紋的效果。

NavigationBarView主負責UI的初始化工作,實例化布局,根據屏幕方向先取正確的圖片。

NavigationBar按鈕的事件綁定

NavigationBar按鈕上的事件綁定其實不是在NavigationBarView里實現,而是在SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java類中完成的。

通過NavigationBarView對外提供的獲得按鈕接口來完成按鈕的綁定:

Recent, Home, SearchLight按鈕事件的綁定

private void prepareNavigationBarView() { mNavigationBarView.reorient(); mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener); mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPreloadOnTouchListener); mNavigationBarView.getHomeButton().setOnTouchListener(mHomeSearchActionListener); mNavigationBarView.getSearchLight().setOnTouchListener(mHomeSearchActionListener); updateSearchPanel(); }

Menu, Home, Back按鈕事件的綁定:

上面3個按鈕都是KeyButtonView類,它們的事件響應進程都是在類本身里面完成的。它們通過onTouchEvent()方法來響應點擊事件,

public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getAction(); int x, y; switch (action) { case MotionEvent.ACTION_DOWN: //Slog.d("KeyButtonView", "press"); mDownTime = SystemClock.uptimeMillis(); setPressed(true); if (mCode != 0) { sendEvent(KeyEvent.ACTION_DOWN, 0, mDownTime); } else { // Provide the same haptic feedback that the system offers for virtual keys. performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); } if (mSupportsLongpress) { removeCallbacks(mCheckLongPress); postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout()); } break; case MotionEvent.ACTION_MOVE: x = (int)ev.getX(); y = (int)ev.getY(); setPressed(x >= -mTouchSlop && x < getWidth() + mTouchSlop && y >= -mTouchSlop && y < getHeight() + mTouchSlop); break; case MotionEvent.ACTION_CANCEL: setPressed(false); if (mCode != 0) { sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED); } if (mSupportsLongpress) { removeCallbacks(mCheckLongPress); } break; case MotionEvent.ACTION_UP: final boolean doIt = isPressed(); setPressed(false); if (mCode != 0) { if (doIt) { sendEvent(KeyEvent.ACTION_UP, 0); sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); playSoundEffect(SoundEffectConstants.CLICK); } else { sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED); } } else { // no key code, just a regular ImageView if (doIt) { performClick(); } } if (mSupportsLongpress) { removeCallbacks(mCheckLongPress); } break; } return true; }

mCode是用來判斷該觸摸是來自于哪一個button,表示不同button的keycode在KeyEvent中類都有定義。該值在布局文件中通過獲得navigationbar_view中的systemui:keycode屬性來取得,下面是layout布局文件中back相應代碼段:

<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back" android:layout_width="@dimen/navigation_key_width" android:layout_height="match_parent" android:src="@drawable/ic_sysbar_back" systemui:keyCode="4" android:layout_weight="0" android:scaleType="center" systemui:glowBackground="@drawable/ic_sysbar_highlight" android:contentDescription="@string/accessibility_back" />

在onTouch中方法通過sendEvent()方法來履行不同的keycode響應事件,該方法會創建1個包括keycode的KeyEvent對象封裝,然后通過injectInputEvent()向InputManager插入1個事件,再發送出去。

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 久久久久久久久免费 | 亚洲永久网站 | 日本爱爱视频 | 中文字幕不卡在线 | 一区二区三区在线播放 | 精品在线一区二区 | 久久免费视频网 | 中文字幕www | 中文字幕一区二区三区四区不卡 | 亚洲网站在线播放 | 亚洲欧洲视频在线 | 国产丝袜一区二区三区免费视频 | 天堂中文字幕在线 | 久久九九免费 | 黄色大片电影 | 国产视频在线免费观看 | 伊人国产精品 | 中文字幕在线观看一区二区 | 国产精品国产三级国产a | 精品国产1区 | 久久久国产精品视频 | 国产成人精品一区二区三区网站观看 | 日本一区二区三区久久久 | 精品国产一区二区在线 | 黄色片在线看 | 玖玖玖视频 | 免费av网站观看 | 最新日韩精品 | 成人国产精品久久久按摩 | h亚洲| 亚洲视频精品在线 | 精品视频在线免费 | 久热99 | 狠狠淫xx | 久久三级网站 | 91天天综合| 中文字幕偷拍 | 婷婷欧美 | 欧美日本韩国一区二区三区 | 久久精品久久久久久 | 国产精品久久久久久一区二区 |