安卓选择器类库,包括日期及时间选择器(可用于出生日期、营业时间等)、单项选择器(可用于性别、民族、职业、学历、星座等)、二三级联动选择器(可用于车牌号、基金定投日期等)、城市地址选择器(分省级、地市级及区县级)、数字选择器(可用于年龄、身高、体重、温度等)、日历选日期择器(可用于酒店及机票预定日期)、颜色选择器、文件及目录选择器等……
api("com.github.gzu-liyujiang.AndroidPicker:WheelPicker:4.1.13")
//日期弹窗demo
context.getActivity()?.let {
DialogConfig.setDialogStyle(DialogStyle.Default) // 或 DialogStyle.Two
val picker: DatePicker = DatePicker(it)
// 拿到确认按钮(TitleBar 的右按钮)
val okBtn = picker.okView // 库内部 ID
okBtn?.setTextColor(ThemeManager.getColor(R.color.color_44d564)) // 改为任意颜色
picker.setBackgroundColor(CornerRound.Top, DialogConfig.getDialogColor().contentBackgroundColor())
picker.getWheelLayout().setResetWhenLinkage(false)
picker.wheelLayout.setDateMode(DateMode.YEAR_MONTH)
picker.wheelLayout.setRange(DateEntity.target(2018, 1, 1), DateEntity.target(2050, 12, 31), DateEntity.today());
picker.show()
picker.setOnDatePickedListener { year, month, day ->
showCopyToast("$year--$month")
}
}
修改样式 如图
package global.view
import android.app.Activity
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.StyleRes
import com.github.gzuliyujiang.wheelpicker.DatePicker
import com.github.gzuliyujiang.wheelpicker.widget.DateWheelLayout
/**
* 带 12dp 圆角(左上+右上)的日期选择器
* @author 你的名字
*/
class DatePickerNew @JvmOverloads constructor(
activity: Activity,
@StyleRes themeResId: Int = 0
) : DatePicker(activity, themeResId) {
override fun createBodyView(): View {
// 原 wheelLayout
wheelLayout = DateWheelLayout(activity)
wheelLayout.setTextSize(16 * activity.getResources().getDisplayMetrics().scaledDensity)
wheelLayout.setSelectedTextSize(
16 * activity.getResources().getDisplayMetrics().scaledDensity
)
wheelLayout.setSelectedTextBold(true)
wheelLayout.setCurtainEnabled(true)
wheelLayout.setCurtainColor(-0xb0b0c)
wheelLayout.setCurtainRadius(8 * activity.getResources().getDisplayMetrics().density)
val padding = (16 * activity.getResources().getDisplayMetrics().density.toInt())
wheelLayout.setPadding(padding, 0, padding, 0)
return wheelLayout
}
}
使用
//日期弹窗demo
context.getActivity()?.let {
DialogConfig.setDialogStyle(DialogStyle.Default) // 或 DialogStyle.Two
val picker: DatePicker = DatePickerNew(it)
// 拿到确认按钮(TitleBar 的右按钮)
val okBtn = picker.okView // 库内部 ID
okBtn?.setTextColor(ThemeManager.getColor(R.color.color_44d564)) // 改为任意颜色
picker.setBackgroundColor(CornerRound.Top, ThemeManager.getThemeColor(R.attr.color_ffffff_191a1b))
// picker.getWheelLayout().setResetWhenLinkage(false)
picker.wheelLayout.setDateMode(DateMode.YEAR_MONTH)
picker.wheelLayout.setRange(DateEntity.target(2018, 1, 1), DateEntity.target(2050, 12, 31), DateEntity.today());
picker.show()
picker.setOnDatePickedListener { year, month, day ->
showCopyToast("$year--$month")
}
}