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

Android 日常整理(三):textAppearance 與軟鍵盤彈出判斷

編輯:關於 Android 程式設計

android:textAppearance 文字外觀設置

在 XML 佈局裡可以設置文字的外觀,例如:

 android:textAppearance="?android:attr/textAppearanceLargeInverse"

這裡引用的是系統自帶的一個外觀,前面的問號表示判斷系統是否存在這種外觀,若不存在則使用默認外觀。

可設置的取值如下:

textAppearanceButton、textAppearanceInverse、textAppearanceLarge、textAppearanceLargeInverse、textAppearanceMedium、textAppearanceMediumInverse、textAppearanceSmall、textAppearanceSmallInverse。

通過 textAppearance,我們無需在每個 TextView 上逐一設置字號、字體顏色等屬性,就能快速套用統一的文字風格,讓界面更加協調一致。

Android 判斷軟鍵盤是否彈出

 // 判斷隱藏軟鍵盤是否彈出
if (getWindow().getAttributes().softInputMode
        == WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
    // 隱藏軟鍵盤
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}

這段代碼通過檢查當前窗口的 softInputMode 是否為 SOFT_INPUT_STATE_UNSPECIFIED,來判斷軟鍵盤的初始狀態,並在需要時將其設置為隱藏。掌握了這個判斷邏輯,就能更精細地控制鍵盤的顯示與隱藏時機,提升用戶的輸入體驗。

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