需要导入依赖:implementation 'com.airsaid.library:pickerviewlibrary:1.0.0'
package com.sf.ceshi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import com.airsaid.pickerviewlibrary.TimePickerView;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView text=findViewById(R.id.textview);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final TimePickerView timePickerView = new TimePickerView(MainActivity.this, TimePickerView.Type.MONTH_DAY_HOUR_MIN);
timePickerView.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {
@Override
public void onTimeSelect(Date date) {
final String timeFormat = new SimpleDateFormat("20yy-MM-dd HH:mm", Locale.getDefault()).format(date);
text.setText(timeFormat);
}
});
timePickerView.show();
}
});
}
}
时间选择器
最新推荐文章于 2022-05-10 17:40:15 发布