Android顏色選擇器:HSV-Alpha Color Picker for Android

jopen 9年前發布 | 25K 次閱讀 Android Android開發 移動開發

這個庫實現了一個顏色選擇器和顏色偏好設置的Android應用程序。

Portrait Landscape Preferences

Features

I couldn't find this combination of features in an existing library, which is why I wrote this one:

  • Alpha slider.
  • Text field to copy and paste hex color values.
  • Old and new colors displayed side by side.
  • Optional selection of "no color".
  • Proper behavior when orientation changes.
  • Up-to-date design.

In addition, the Hue-Saturation picker...

  • gives higher hue precision than a square picker of the same size.
  • allows easier selection of pure white than a circular picker.

Using the Library

Add the library dependency to your app module's build.gradle:

dependencies {
    compile 'com.rarepebble:colorpicker:1.0.0'
}

Add jcenter() to your repository list if it isn't there already.

ColorPreference Usage

Add the ColorPreference to your preference screen xml. Don't forget the extra xmlns: declaration:

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.rarepebble.colorpicker.ColorPreference
        android:key="simplePreference"
        android:title="@string/pref_title"
        app:colorpicker_defaultColor="#f00"
        />

</PreferenceScreen>

To use the "optional color" functionality, specify a button label for the "no colour" button:
    <com.rarepebble.colorpicker.ColorPreference
        android:key="myOptionalColor"
        android:title="@string/pref_optional_color"
        app:colorpicker_selectNoneButtonText="@string/no_color"
        app:colorpicker_noneSelectedSummaryText="@string/no_color_selected"
        />

You can also specify some summary text to be shown when there is no color chosen, as in the example here. The "No color" choice is saved by removing the saved preference, so use SharedPreference.contains("myOptionalColor") to test for that.

ColorPickerView Usage

For many people, the ColorPreference will be all that's needed, but if you wish to use the ColorPickerView directly, it can be constructed in the usual way, either in code or in a layout. Set the initial color with setColor() and retrieve the view's current color with getColor():

final ColorPickerView picker = new ColorPickerView(getContext());
picker.setColor(0xff12345);
...
final int color = picker.getColor();

項目主頁:http://www.baiduhome.net/lib/view/home/1438863989036

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!