標籤:des android style blog http io ar color sp
有些Android裝置沒有實體的音量大小按鈕,或者從保護實體按鍵的角度考慮,就需要在導覽列的虛擬按鍵中添加音量加減調節按鍵。
在這裡我推薦一下比較好的android源碼片段網站:http://code.662p.com/list/173_1.html
效果如所示:
實現過程如下:
1.首先在SystemUI中添加音量加減的資源檔,路徑如下:
frameworks/base/packages/SystemUI/res/
將圖片放入對應的drawable檔案夾,包括音量+,和音量-,見。
2.修改導覽列的布局檔案,路徑:
frameworks/base/packages/SystemUI/res/
在對應的layout檔案夾中找到navigation_bar.xml檔案進行修改:
在返回鍵前面添加“音量減”,返回鍵的布局:
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back" android:layout_width="128dp" android:paddingStart="25dp" android:paddingEnd="25dp" android:layout_height="match_parent" android:src="@drawable/ic_sysbar_back" systemui:keyCode="4" android:layout_weight="0" systemui:glowBackground="@drawable/ic_sysbar_highlight" android:contentDescription="@string/accessibility_back" />
詳細說明:http://android.662p.com/thread-6038-1-1.html
Android在導覽列添加音量加減按鈕安卓源碼案例