我的代码OnCreateView
扩展了BottomSheetDialogFragment
,但它会出现在屏幕底部...
他们的方式/代码会改变其位置从下到上吗?
请看这张图片:
这是我的代码ModalEvent.java :
package com.example.khalessi_jb.reminderapplication;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import java.util.Calendar;
public class ModalEvent extends BottomSheetDialogFragment implements View.OnClickListener {
TextView txtDateandTime;
Button btnsDateTime;
TextView txtTime;
Button btnTime;
Button btnCloseEvent;
Calendar calendar;
DatePickerDialog datePickerDialog;
TimePickerDialog timePickerDialog;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.modal_event,container,false);
btnsDateTime = (Button) v.findViewById(R.id.btnDate);
txtDateandTime =(TextView)v.findViewById(R.id.txtDate);
btnTime =(Button)v.findViewById(R.id.btnTime);
txtTime =(TextView)v.findViewById(R.id.txtTime);
btnCloseEvent = (Button)v.findViewById(R.id.btnCloseEvent);
btnsDateTime.setOnClickListener(this);
btnCloseEvent.setOnClickListener(this);
btnTime.setOnClickListener(this);
return v;
}
@Override
public void onClick(View v) {
if(v==btnTime){
calendar = Calendar.getInstance();
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes =calendar.get(Calendar.MINUTE);
timePickerDialog = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String amPm;
if(hourOfDay >= 12){
amPm="PM";
}else{
amPm="AM";
}
if(hourOfDay > 12){
hourOfDay = hourOfDay - 12;
}
else if(hourOfDay == 0){
hourOfDay=12;
}
txtTime.setText(String.format("%02d:%02d", hourOfDay, minute)+amPm);
}
},hour,minutes,false);
timePickerDialog.show();
}
if(v==btnsDateTime){
calendar = Calendar.getInstance();
int daysss = calendar.get(Calendar.DAY_OF_MONTH);
int monthss =calendar.get(Calendar.MONTH);
int yearss =calendar.get(Calendar.YEAR);
datePickerDialog = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int mYear, int mMonth, int mDay) {
txtDateandTime.setText(mDay +"/" + (mMonth +1)+"/"+mYear);
}
},yearss,monthss,daysss);
datePickerDialog.show();
}
if(v==btnCloseEvent){
dismiss();
}
}
}