Android PickerView シンプルなアプリケーション

1. Android-ピッカービュー

Android-PickerView は、PickerView時間セレクターとオプション セレクターを備えたiOS に似たコントロールです。

依存関係を追加する

implementation 'com.contrarywind:Android-PickerView:4.1.9'

2. タイムピッカー

Android-PickerViewタイムピッカーBuildはパターンを使用して作成されます

var timePickerView = TimePickerBuilder(context) {
    
     date, v ->
        }.build()
timePickerView.show()

以下のように表示します

ここに画像の説明を挿入

TimePickerBuilderメインメソッド

方法 説明する
setType(boolean[] 型) 「年」、「月」、「日」、「時」、「分」、「秒」のそれぞれの表示・非表示を制御します。タイプの長さは6です。
setDate(カレンダーの日付) Calendarのsetメソッドを呼び出して時刻を設定します。
setRangDate(カレンダー開始日, カレンダー終了日) 開始時間を設定する
setCancelText(String textContentCancel) キャンセルボタンのテキストを設定する
setCancelColor(int textColorCancel) キャンセル文字色を設定する
setSubmitText(String textContentconfirm) 確認ボタンのテキストを設定する
setSubmitColor(int textColorconfirm) 確認テキストの色を設定する
setSubCalSize(int textSizeSubmitCancel) キャンセルボタンと確認ボタンのテキストサイズを設定する
setTitleText(String textContentTitle) タイトルテキストを設定する
setTitleColor(int textColorTitle) タイトルの文字色を設定する
setTitleSize(int textSizeTitle) タイトルの文字サイズを設定する
setTitleBgColor(int bgColorTitle) タイトルバーの色を設定する
setBgColor(int bgColorWheel) 背景色を設定する
setOutSideColor(int outSideColor) 外部の背景色を設定します。デフォルトはグレーです。
setContentTextSize(int textSizeContent) コンテンツのテキストサイズを設定する
setItemVisibleCount(int カウント) 表示される数値を設定します。できれば奇数です。デフォルトは 9 です。
setTextColorCenter(int textColorCenter) 分割線間のテキストの色を設定します。
setTextColorOut(int textColorOut) 分割線の外側の文字の色を設定します。
setDividerColor(int dividerColor) 分割線の色を設定する
setDividerType(WheelView.DividerType ディバイダータイプ) 分割線のスタイルを設定します。デフォルトは FILL です。
setLineSpacingMultiplier(float lineSpacingMultiplier) 間隔乗数を設定します。1.0 ~ 4.0f の間でのみ指定できます。デフォルトは 1.6 です。
isCyclic(ブール値巡回) アイテムがループするかどうか
setLabel(文字列, 文字列, 文字列, 文字列, 文字列, 文字列) デフォルト設定は年、月、日、時、分、秒です。
isCenterLabel(ブール値 isCenterLabel) 中央で選択されている項目のラベルテキストのみを表示するかどうか
setOutSideCancelable(ブール値キャンセル可能) 外側をクリックしてキャンセルを許可するかどうか
isDialog(ブール値 isDialog) ダイアログモードですか
setDecorView(ViewGroupdecoView) セレクターがこのコンテナに追加されます

カスタムパラメータ

var timePickerView = TimePickerBuilder(this) {
    
     date, v ->

}.setType(booleanArrayOf(true, true, true, true, false, false))
    .setCancelText("Cancel")
    .setCancelColor(Color.GRAY)
    .setSubmitText("Confirm")
    .setSubmitColor(Color.MAGENTA)
    .setSubCalSize(15)
    .setTitleText("Title")
    .setTitleColor(Color.RED)
    .setTitleSize(25)
    .setTitleBgColor(Color.BLACK)
    .setBgColor(Color.BLACK)
    .setContentTextSize(20)
    .setItemVisibleCount(11)
    .setTextColorCenter(Color.RED)
    .setTextColorOut(Color.MAGENTA)
    .setOutSideColor(Color.GRAY)
    .setDividerColor(Color.CYAN)
    .setDividerType(WheelView.DividerType.WRAP)
    .setLineSpacingMultiplier(2.5f)
    .isCyclic(true)
    .isCenterLabel(true)
    .build()

timePickerView.show()

以下のように表示します

ここに画像の説明を挿入

3. オプションセレクター

Android-PickerViewオプション セレクターもBuildパターンを使用して作成され、3 レベルのリンクをサポートします。

var optionsPickerView = OptionsPickerBuilder(this) {
    
     option1, option2, option3, v ->

}.build<String>()

optionsPickerView.setNPicker(hourList, minuteList, secondList)

var calendar = Calendar.getInstance()
optionsPickerView.setSelectOptions(calendar.get(Calendar.HOUR_OF_DAY),
    calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND))
optionsPickerView.show()

以下のように表示します

ここに画像の説明を挿入

OptionsPickerBuilderメインメソッド

方法 説明する
setCancelText(String textContentCancel) キャンセルボタンのテキストを設定する
setCancelColor(int textColorCancel) キャンセル文字色を設定する
setSubmitText(String textContentconfirm) 確認ボタンのテキストを設定する
setSubmitColor(int textColorconfirm) 確認テキストの色を設定する
setSubCalSize(int textSizeSubmitCancel) キャンセルボタンと確認ボタンのテキストサイズを設定する
setTitleText(String textContentTitle) タイトルテキストを設定する
setTitleColor(int textColorTitle) タイトルの文字色を設定する
setTitleSize(int textSizeTitle) タイトルの文字サイズを設定する
setTitleBgColor(int bgColorTitle) タイトルバーの色を設定する
setBgColor(int bgColorWheel) 背景色を設定する
setOutSideColor(int outSideColor) 外部の背景色を設定します。デフォルトはグレーです。
setContentTextSize(int textSizeContent) コンテンツのテキストサイズを設定する
setItemVisibleCount(int カウント) 表示される数値を設定します。できれば奇数です。デフォルトは 9 です。
setTextColorCenter(int textColorCenter) 分割線間のテキストの色を設定します。
setTextColorOut(int textColorOut) 分割線の外側の文字の色を設定します。
setDividerColor(int dividerColor) 分割線の色を設定する
setDividerType(WheelView.DividerType ディバイダータイプ) 分割線のスタイルを設定します。デフォルトは FILL です。
setLineSpacingMultiplier(float lineSpacingMultiplier) 間隔乗数を設定します。1.0 ~ 4.0f の間でのみ指定できます。デフォルトは 1.6 です。
setCyclic(ブール値 cyclic1, ブール値 cyclic2, ブール値 cyclic3) アイテムがループするかどうか
setLabels(文字列ラベル1, 文字列ラベル2, 文字列ラベル3) 単位文字を設定する
isCenterLabel(ブール値 isCenterLabel) 中央で選択されている項目のラベルテキストのみを表示するかどうか
setOutSideCancelable(ブール値キャンセル可能) 外側をクリックしてキャンセルを許可するかどうか
isDialog(ブール値 isDialog) ダイアログモードですか
setDecorView(ViewGroupdecoView) セレクターがこのコンテナに追加されます
isRestoreItem(boolean isRestoreItem) オプションを切り替えるとき、後のオプションを復元するかどうか、デフォルトでは前のオプションが保持されます。

カスタムパラメータ

var optionsPickerView = OptionsPickerBuilder(this) {
    
     option1, option2, option3, v ->
}.setCancelText("Cancel")
    .setCancelColor(Color.GRAY)
    .setSubmitText("Confirm")
    .setSubmitColor(Color.MAGENTA)
    .setSubCalSize(15)
    .setTitleText("Title")
    .setTitleColor(Color.RED)
    .setTitleSize(25)
    .setTitleBgColor(Color.BLACK)
    .setBgColor(Color.BLACK)
    .setContentTextSize(20)
    .setItemVisibleCount(11)
    .setTextColorCenter(Color.RED)
    .setTextColorOut(Color.MAGENTA)
    .setOutSideColor(Color.GRAY)
    .setDividerColor(Color.CYAN)
    .setDividerType(WheelView.DividerType.WRAP)
    .setLineSpacingMultiplier(2.5f)
    .setCyclic(false, true, true)
    .setLabels("时", "分", "秒")
    .isCenterLabel(true)
    .build<String>()

optionsPickerView.setNPicker(hourList, minuteList, secondList)
var calendar = Calendar.getInstance()
optionsPickerView.setSelectOptions(calendar.get(Calendar.HOUR_OF_DAY),
    calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND))

optionsPickerView.show()

以下のように表示します
ここに画像の説明を挿入

オプションの内容をOptionsPickerView内部に設定する必要があります

方法 説明する
setPicker(オプション項目のリスト) 連携オプションを設定する
setPicker(List options1Items, List<List> options2Items) 連携オプションを設定する
setPicker(List options1Items, List<List> options2Items, List<List<List>> options3Items) 連携オプションを設定する
setNPicker(オプション 1 項目のリスト, オプション 2 項目のリスト, オプション 3 項目のリスト) 非連動時に使用する設定オプション
setSelectOptions(int オプション 1) デフォルトの選択を設定する
setSelectOptions(int オプション 1, int オプション 2) デフォルトの選択を設定する
setSelectOptions(int オプション 1, int オプション 2, int オプション 3) デフォルトの選択を設定する

連携項目を設定し、オプションを切り替えると次の項目をリセットします

var optionsPickerView = OptionsPickerBuilder(this) {
    
     option1, option2, option3, v ->

}.isRestoreItem(true)
    .setItemVisibleCount(11)
    .build<String>()

optionsPickerView.setPicker(provinceList, cityList, areaList)
optionsPickerView.setSelectOptions(2, 5, 5)
optionsPickerView.show(v)

以下のように表示します

ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/chennai1101/article/details/130641768