安卓:日期选择器从日历中被弹 [英] Android: date picker from calendar popdown
问题描述
在我的应用程序的用户应该通过单击编辑文字,对于目前我使用日期选择器对话框,其工作良好,但选择一个日期,它就像打开另一个对话框和所有。所以我想展示它像弹出下拉菜单,结账的知情同意。请大家帮我实现这一目标!
In my app user should select a date by clicking on Edit Text, for that currently i'm using a date picker dialog and its working good but its like opening another dialog and all. so i thought of showing it like pop down menu, checkout the pic. please help me to achieve this!
推荐答案
您只需要创建一个新的弹出窗口和膨胀日历查看到该窗口:按照以下步骤操作:
You just create a New Popup window and inflate calender view into that window: follow the below steps:
edit_text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showPopup(MainActivity.this);
}
});
现在showPopup()方法:
Now showPopup() method:
// The method that displays the popup.
private void showPopup(Activity context) {
// Inflate the popup_layout.xml
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = layoutInflater.inflate(R.layout.main3, null,false);
// Creating the PopupWindow
final PopupWindow popupWindow = new PopupWindow(
layout,400,400);
popupWindow.setContentView(layout);
popupWindow.setHeight(500);
popupWindow.setOutsideTouchable(false);
// Clear the default translucent background
popupWindow.setBackgroundDrawable(new BitmapDrawable());
CalendarView cv = (CalendarView) layout.findViewById(R.id.calendarView);
cv.setBackgroundColor(Color.BLUE);
cv.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month,
int dayOfMonth) {
// TODO Auto-generated method stub
popupWindow.dismiss();
Log.d("date selected", "date selected " + year + " " + month + " " + dayOfMonth);
}
});
popupWindow.showAtLocation(layout, Gravity.TOP,5,170);
}
现在,main3.xml文件:
Now, main3.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="400dp"
android:clickable="true"
android:showWeekNumber="false" />
</LinearLayout>
和正下方卡扣看看,你会被你的自我确定定制这个弹出窗口。
and just below snap have a look and you'll customized this popup window by your self ok.
这篇关于安卓:日期选择器从日历中被弹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!