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

Android 為 EditText 與 AutoCompleteTextView 自訂文字選取顏色

編輯:關於 Android 程式設計

大多數 Android ROM 上,文字選取時的背景色都是清爽的鮮綠色,但在某些三星手機上卻是藍色,觀感實在不佳。好消息是,這個預設的選取背景色完全可以透過程式自行調整。

需要用到的 API 是:

android:textColorHighlight  Color of the text selection highlight.

EditText 的效果

AutoCompleteTextView 的效果

實作程式碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <EditText
      android:id="@+id/et_inputBox"
      android:layout_height="wrap_content"
      android:layout_width="match_parent"
      android:textColorHighlight="#B4DF87"
        />
    <AutoCompleteTextView
        android:id="@+id/act_input"
        android:layout_below="@id/et_inputBox"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
      android:textColorHighlight="#B4DF87"
        />
</LinearLayout>

只要為控制項加上 android:textColorHighlight 並指定喜歡的色值,就能自訂文字選取時的高亮色彩,讓介面更貼近品牌調性。

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