GitHub
Android-PickerView绝不仅仅只能实现时间选择,还能实现省市区等联动效果,更多使用请戳→GitHub
时间选择器效果图
先用起来
添加依赖
compile 'com.contrarywind:Android-PickerView:4.1.6'
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_time"
android:hint="8:00"
android:textSize="16sp"
/>
<Button
android:id="@+id/btn_choose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="choose"/>
</LinearLayout>
MainActivity
public class MainActivity extends Activity implements View.OnClickListener{
private TextView textView;
private Button button;
private TimePickerView pvTime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.tv_time);
button = findViewById(R.id.btn_choose);
button.setOnClickListener(this);
initTimePicker();
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.btn_choose:
if (pvTime != null) {
pvTime.show(view);//弹出时间选择器,传递参数过去,回调的时候则可以绑定此view
}
break;
}
}
private void initTimePicker() {//Dialog 模式下,在底部弹出
pvTime &