Android PickerView simple application

1. Android-PickerView

Android-PickerView is an iOS-like PickerViewcontrol with a time selector and an option selector.

add dependencies

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

2. Time Picker

Android-PickerViewTimepickers Buildare created using the pattern

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

show as below

insert image description here

TimePickerBuildermain method

method illustrate
setType(boolean[] type) Respectively control the display or hide of "year", "month", "day", "hour", "minute" and "second", the length of type is 6
setDate(Calendar date) Call the set method of Calendar to set the time
setRangDate(Calendar startDate, Calendar endDate) set start time
setCancelText(String textContentCancel) Set cancel button text
setCancelColor(int textColorCancel) Set cancel text color
setSubmitText(String textContentConfirm) Set confirm button text
setSubmitColor(int textColorConfirm) Set confirmation text color
setSubCalSize(int textSizeSubmitCancel) Set cancel and confirm button text size
setTitleText(String textContentTitle) set title text
setTitleColor(int textColorTitle) Set title text color
setTitleSize(int textSizeTitle) Set title text size
setTitleBgColor(int bgColorTitle) Set the title bar color
setBgColor(int bgColorWheel) set background color
setOutSideColor(int outSideColor) Set the external background color, the default is gray
setContentTextSize(int textSizeContent) Set content text size
setItemVisibleCount(int count) Set the visible number, preferably an odd number, the default is 9
setTextColorCenter(int textColorCenter) Sets the color of the text between the dividing lines
setTextColorOut(int textColorOut) Set the color of the text outside the dividing line
setDividerColor(int dividerColor) Set the dividing line color
setDividerType(WheelView.DividerType dividerType) Set the dividing line style, the default is FILL
setLineSpacingMultiplier(float lineSpacingMultiplier) Set the interval multiplier, it can only be between 1.0-4.0f, the default is 1.6
isCyclic(boolean cyclic) Whether item loops
setLabel(String, String, String, String, String, String) The default setting is year, month, day, hour, minute, and second
isCenterLabel(boolean isCenterLabel) Whether to display only the label text of the middle selected item
setOutSideCancelable(boolean cancelable) Whether to allow clicking outside to cancel
isDialog(boolean isDialog) Is it dialog mode
setDecorView(ViewGroup decorView) The selector will be added to this container

Custom parameters

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()

show as below

insert image description here

3. Option selector

Android-PickerViewOption selectors are also Buildcreated using patterns and support 3 levels of linkage.

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()

show as below

insert image description here

OptionsPickerBuildermain method

method illustrate
setCancelText(String textContentCancel) Set cancel button text
setCancelColor(int textColorCancel) Set cancel text color
setSubmitText(String textContentConfirm) Set confirm button text
setSubmitColor(int textColorConfirm) Set confirmation text color
setSubCalSize(int textSizeSubmitCancel) Set cancel and confirm button text size
setTitleText(String textContentTitle) set title text
setTitleColor(int textColorTitle) Set title text color
setTitleSize(int textSizeTitle) Set title text size
setTitleBgColor(int bgColorTitle) Set the title bar color
setBgColor(int bgColorWheel) set background color
setOutSideColor(int outSideColor) Set the external background color, the default is gray
setContentTextSize(int textSizeContent) Set content text size
setItemVisibleCount(int count) Set the visible number, preferably an odd number, the default is 9
setTextColorCenter(int textColorCenter) Sets the color of the text between the dividing lines
setTextColorOut(int textColorOut) Set the color of the text outside the dividing line
setDividerColor(int dividerColor) Set the dividing line color
setDividerType(WheelView.DividerType dividerType) Set the dividing line style, the default is FILL
setLineSpacingMultiplier(float lineSpacingMultiplier) Set the interval multiplier, it can only be between 1.0-4.0f, the default is 1.6
setCyclic(boolean cyclic1, boolean cyclic2, boolean cyclic3) Whether item loops
setLabels(String label1, String label2, String label3) set unit character
isCenterLabel(boolean isCenterLabel) Whether to display only the label text of the middle selected item
setOutSideCancelable(boolean cancelable) Whether to allow clicking outside to cancel
isDialog(boolean isDialog) Is it dialog mode
setDecorView(ViewGroup decorView) The selector will be added to this container
isRestoreItem(boolean isRestoreItem) When switching options, whether to restore the latter option, the default is to keep the previous option

Custom parameters

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()

show as below
insert image description here

The option content needs to OptionsPickerViewbe set inside

method illustrate
setPicker(List optionsItems) Set linkage options
setPicker(List options1Items, List<List> options2Items) Set linkage options
setPicker(List options1Items, List<List> options2Items, List<List<List>> options3Items) Set linkage options
setNPicker(List options1Items, List options2Items, List options3Items) Setting options, used in non-linkage
setSelectOptions(int option1) set default selection
setSelectOptions(int option1, int option2) set default selection
setSelectOptions(int option1, int option2, int option3) set default selection

Set the linkage item, when switching options, reset the next item

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)

show as below

insert image description here

Guess you like

Origin blog.csdn.net/chennai1101/article/details/130641768