Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

在 Android 4.2 鎖屏界面中添加解鎖項

編輯:關於 Android 程式設計

Android 4.2 的系統預設解鎖方式,是把圓環滑動到任意位置即可解鎖。若想讓解鎖界面像原生那樣多出相機、Google 搜尋等捷徑入口,只需要動一個關鍵的佈局檔即可。

修改 GlowPadView 佈局

打開 frameworks/base/core/res/res/layout/keyguard_glow_pad_view.xml,找到設定目標項的屬性,把「僅解鎖」的陣列換成「含相機」的陣列:

- prvandroid:targetDrawables="@array/lockscreen_targets_unlock_only"
- prvandroid:targetDescriptions="@array/lockscreen_target_descriptions_unlock_only"
+ prvandroid:targetDrawables="@array/lockscreen_targets_with_camera"
+ prvandroid:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"

改動的邏輯很直白:lockscreen_targets_unlock_only 只包含解鎖這一項,而 lockscreen_targets_with_camera 則在解鎖之外額外提供了相機(以及原生版本中的 Google 搜尋)等目標。把這兩組屬性由前者替換成後者,重新編譯後,鎖屏時就會預設多出相機與搜尋捷徑。

添加自訂解鎖項

如果想要的是完全自訂的解鎖內容,做法也一致:參照 Android 原生的模板,在對應的 array 資源中新增或修改 targetDrawables 與 targetDescriptions 的內容,並提供相應的圖示與描述字串即可。掌握「目標陣列決定解鎖界面有哪些入口」這個核心概念後,無論是沿用原生配置還是自創捷徑,都能得心應手。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved