Android之PopupWindow,dialog设置日期
来源:互联网 发布:邢台网络推广招聘 编辑:程序博客网 时间:2024/06/01 09:06
传承者(Inheritors)打造共同进步生态圈!!!
Thinking
PopupWindow的布局,调用PopupWindow
PopupWindow的简单布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" ><TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="Hello PopupWindow"/></RelativeLayout>
activity
public class Main2Activity extends AppCompatActivity { private Button button; private Handler mHandler = new Handler(){ @Override public void handleMessage(Message msg) { switch (msg.what){ case 1: showPopupWindow(); break; } } }; private void showPopupWindow() { Context mContext = Main2Activity.this; LayoutInflater mLayoutInflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View music_popupWindow = mLayoutInflater.inflate(R.layout.activity_main,null); PopupWindow mPopupWindow = new PopupWindow(music_popupWindow, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mPopupWindow.showAtLocation(findViewById(R.id.rel), Gravity.CENTER,0,0); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); button = (Button) findViewById(R.id.popupwindow); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Timer timer = new Timer(); timer.schedule(new InitPopupWindow(),100); } }); } private class InitPopupWindow extends TimerTask{ @Override public void run() { Message message = Message.obtain(); message.what = 1; mHandler.sendMessage(message); } }}
其他布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:id="@+id/rel" tools:context="com.example.administrator.testapplication.Main2Activity"> <Button android:id="@+id/popupwindow" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="show PopupWindow" /></RelativeLayout>
dialog设置日期
new DatePickerFragment().show(getFragmentManager(), "datePicker");
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); return new DatePickerDialog(getActivity(), this, year, month, day); } @Override public void onDateSet(DatePicker view, int year, int month, int day) { customerBirthday.setText(year+"-"+(month+1)+"-"+day); Log.d("OnDateSet", "select year:"+year+";month:"+month+";day:"+day); } }
设置日期
private void showBirthdayChooseDialog() {// //获取当前的年、月、日 Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); final int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); //通过自定义控件AlertDialog实现 AlertDialog.Builder builder = new AlertDialog.Builder(this); View view = (LinearLayout) getLayoutInflater().inflate(R.layout.date_dialog_layout, null); final DatePicker datePicker = (DatePicker) view.findViewById(R.id.date_picker); datePicker.init(year, month, day, null); //设置date布局 builder.setView(view); builder.setTitle("选择出生日期"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //日期格式 StringBuffer sb = new StringBuffer(); sb.append(String.format("%d-%02d-%02d", datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth())); customerBirthday.setText(sb); dialog.cancel(); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.create().show(); }
private void showBirthdayChooseDialog() {// //获取当前的年、月、日 Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); final int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { customerBirthday.setText(year+"-"+(monthOfYear+1)+"-"+dayOfMonth); } },year,month,day).show();}
0 0
- Android之PopupWindow,dialog设置日期
- Android之自定义AlertDialog和PopupWindow实现(仿微信Dialog)
- Android之自定义AlertDialog和PopupWindow实现(仿微信Dialog)
- Android 透明(沉浸)状态栏之Dialog和PopupWindow
- android.widget.PopupWindow,生成Dialog
- Android弹窗合集(PopupWindow,dialog)
- 自定义Dialog、带时间和日期的Dialog、PopupWindow、Notification
- Android PopupWindow设置
- Android PopupWindow 相关设置
- Dialog && PopupWindow
- android自定义tabwidget,popupwindow,spinner,dialog,listview
- Android-Popupwindow和Dialog做弹出窗口
- android中Dialog和PopupWindow的区别
- Android自定义Dialog,Toast,Notification和PopupWindow
- android 对话弹出框(Dialog AlertDialog PopupWindow)
- Android中Popupwindow和Dialog的区别
- Android中的Dialog和Popupwindow的区别
- Android的Dialog和PopupWindow的使用
- equals方法
- How to access HBase from spark-shell using YARN as the master on CDH 5.3 and Spark 1.2
- 为什么不能使用Thread.stop()方法?
- int指令
- Maven常用插件介绍:Maven-assembly-plugin插件
- Android之PopupWindow,dialog设置日期
- Android中补间动画的基本使用
- Dynamics CRM2013 导入解决方案(快速视图窗体)SystemForm With Id Does Not Exist的解决方法
- 【Java】form表单提交中文乱码
- BZOJ4204 取球游戏
- 网络游戏同步问题
- struts2的文件上传与下载
- 创建新线程
- 探寻C++最快的读取文件的方案