滚动式选单依然是常用基本元件之一,使用起来也非常容易。直接上图。
选项里面可以放Int或String,方式不太一样。先来看纯数字的怎麽做。
资料来源:台湾漫画基地
放入numberPicker元件,可以设定solidColor跟scrollbar等一些基本设定
<NumberPicker
android:id="@+id/num_year"
android:layout_width="0dp"
android:layout_height="144dp"
android:solidColor="@color/colorFFFFFF"
android:scrollbarSize="5dp"
app:layout_constraintBottom_toTopOf="@id/btn_cancel_birth"
app:layout_constraintEnd_toStartOf="@id/num_month"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginEnd="4dp"
android:layout_marginStart="16dp" />
<NumberPicker
android:id="@+id/num_month"
android:layout_width="0dp"
android:layout_height="144dp"
android:solidColor="@color/colorFFFFFF"
app:layout_constraintBottom_toTopOf="@id/btn_cancel_birth"
app:layout_constraintEnd_toStartOf="@id/num_day"
app:layout_constraintStart_toEndOf="@id/num_year"
android:layout_marginEnd="4dp"/>
<NumberPicker
android:id="@+id/num_day"
android:layout_width="0dp"
android:layout_height="144dp"
android:solidColor="@color/colorFFFFFF"
app:layout_constraintBottom_toTopOf="@id/btn_cancel_birth"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/num_month"
android:layout_marginEnd="16dp"
android:layout_marginStart="4dp"/>
设定每个选单的最大值与最小值,并用xxx.value(getValue)取得使用者选取的值。
num_day.maxValue = 31
num_day.minValue = 1
num_month.maxValue = 12
num_month.minValue = 1
num_year.maxValue = 2020
num_year.minValue = 1990
println("${num_year.value}年${num_month.value}月${num_day.value}日")
Done.
资料来源:台湾漫画基地
<NumberPicker
android:id="@+id/text_picker"
android:layout_width="0dp"
android:layout_height="144dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@color/colorFFFFFF"
android:solidColor="@color/colorFFFFFF"
app:layout_constraintBottom_toTopOf="@id/btn_cancel_txt_picker"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
我们把选项内容的字串放入一个array,并告知系统这个阵列的size为3(0~2)
取资料时,去拿displayedValues这个阵列中的索引值,来取得对应字串。
text_picker.maxValue = 2
text_picker.minValue = 0
text_picker.setDisplayedValues( arrayOf<String>("创作谘询", "媒合谘询", "其他服务"))
println(text_picker.displayedValues[text_picker.value].toString())
Done.
【APP/Android】文字选择器 - NumberPicker 的应用
<<: 好想工作室 web camp JS 怎麽 training
>>: Seagate希捷外接式硬碟机无响应/无法读取/没有回应?
前言 CSS可用来制作简单的动画,效能会比JS好很多。 属性 animation-delay 设定动...
上一篇我们的基因体时代-AI, Data和生物资讯 Day09-合成生物学与机器学习分享合成生物学领...
一. BOW BOW的全名为Bag-of-words,中文是'一袋文字',意思就是将词都丢进一个袋子...
唯心又看了诗忆之前写的几个高阶函式练习。「嗯⋯⋯我觉得你与其说是对高阶函式不熟,不如说是对匿名函式不...
大家好,我是YIYI,今天我要来介绍规格表。 关於规格表 规格表可以帮助大家快速地了解到你所想制作的...