日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android日期時(shí)間選擇器

日期選擇器是很多應(yīng)用所具備的,比如設(shè)置一些任務(wù)的開始和結(jié)束時(shí)間。為了方便用戶的同時(shí)也為了界面的好看,很多都是采用日期選擇器,我在網(wǎng)上看了一下。很多的日期選擇器個(gè)人感覺不是很好看,但是修改起來也有點(diǎn)麻煩,于是自己就寫了一個(gè)demo。至于界面效果個(gè)人感覺也是很low,畢竟鄙人不是搞UI的,所以也就湊合著看吧。這些都不重要,因?yàn)檫@些是可以修改的。

目前創(chuàng)新互聯(lián)建站已為上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、中牟網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

如果想實(shí)現(xiàn)具有年月日的請(qǐng)看下面的注意里面的內(nèi)容,下圖是實(shí)現(xiàn)的分鐘為00 15 30 45的如果想要0-59的請(qǐng)看下面的注意里面的內(nèi)容

如果需要的是仿iOS的帶有星期幾的

首先界面彈出PopupWindow動(dòng)畫的實(shí)現(xiàn),具體的代碼如下

進(jìn)入動(dòng)畫

 
 
 
 
  1.  
  2.  
  3.  
  4.     
  5.         android:duration="500" 
  6.         android:fromYDelta="100.0%p" 
  7.         android:toYDelta="45" /> 
  8.  
  9.   

退出動(dòng)畫

 
 
 
 
  1.  
  2.  
  3.  
  4.     
  5.         android:duration="500" 
  6.         android:fromYDelta="0.0" 
  7.         android:toYDelta="100.0%p" /> 
  8.  
  9.   

主要界面的內(nèi)容

 
 
 
 
  1. public class MainActivity extends Activity implements View.OnClickListener{ 
  2.     private TextView tv_house_time; 
  3.     private TextView tv_center; 
  4.     private WheelMain wheelMainDate; 
  5.     private String beginTime; 
  6.  
  7.     @Override 
  8.     protected void onCreate(Bundle savedInstanceState) { 
  9.         // TODO Auto-generated method stub 
  10.         super.onCreate(savedInstanceState); 
  11.         setContentView(R.layout.activity_main); 
  12.         initView(); 
  13.         initEvent(); 
  14.     } 
  15.  
  16.     private void initEvent() { 
  17.         tv_house_time.setOnClickListener(this); 
  18.     } 
  19.  
  20.     private void initView() { 
  21.         tv_house_time = (TextView) findViewById(R.id.tv_house_time); 
  22.         tv_center = (TextView) findViewById(R.id.tv_center); 
  23.     } 
  24.  
  25.     private java.text.DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
  26.     public void showBottoPopupWindow() { 
  27.         WindowManager manager = (WindowManager)getSystemService(Context.WINDOW_SERVICE); 
  28.         Display defaultDisplay = manager.getDefaultDisplay(); 
  29.         DisplayMetrics outMetrics = new DisplayMetrics(); 
  30.         defaultDisplay.getMetrics(outMetrics); 
  31.         int width = outMetrics.widthPixels; 
  32.                 View menuView = LayoutInflater.from(this).inflate(R.layout.show_popup_window,null); 
  33.         final PopupWindow mPopupWindow = new PopupWindow(menuView, (int)(width*0.8), 
  34.                 ActionBar.LayoutParams.WRAP_CONTENT); 
  35.         ScreenInfo screenInfoDate = new ScreenInfo(this); 
  36.         wheelMainDate = new WheelMain(menuView, true); 
  37.         wheelMainDate.screenheight = screenInfoDate.getHeight(); 
  38.         String time = DateUtils.currentMonth().toString(); 
  39.         Calendar calendar = Calendar.getInstance(); 
  40.         if (JudgeDate.isDate(time, "yyyy-MM-DD")) { 
  41.             try { 
  42.                 calendar.setTime(new Date(time)); 
  43.             } catch (Exception e) { 
  44.                 e.printStackTrace(); 
  45.             } 
  46.         } 
  47.         int year = calendar.get(Calendar.YEAR); 
  48.         int month = calendar.get(Calendar.MONTH); 
  49.         int day = calendar.get(Calendar.DAY_OF_MONTH); 
  50.         int hours = calendar.get(Calendar.HOUR_OF_DAY); 
  51.         int minute = calendar.get(Calendar.MINUTE); 
  52.         wheelMainDate.initDateTimePicker(year, month, day, hours,minute); 
  53.         final String currentTime = wheelMainDate.getTime().toString(); 
  54.         mPopupWindow.setAnimationStyle(R.style.AnimationPreview); 
  55.         mPopupWindow.setTouchable(true); 
  56.         mPopupWindow.setFocusable(true); 
  57.         mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); 
  58.         mPopupWindow.showAtLocation(tv_center, Gravity.CENTER, 0, 0); 
  59.         mPopupWindow.setOnDismissListener(new poponDismissListener()); 
  60.         backgroundAlpha(0.6f); 
  61.         TextView tv_cancle = (TextView) menuView.findViewById(R.id.tv_cancle); 
  62.         TextView tv_ensure = (TextView) menuView.findViewById(R.id.tv_ensure); 
  63.         TextView tv_pop_title = (TextView) menuView.findViewById(R.id.tv_pop_title); 
  64.         tv_pop_title.setText("選擇起始時(shí)間"); 
  65.         tv_cancle.setOnClickListener(new View.OnClickListener() { 
  66.             @Override 
  67.             public void onClick(View arg0) { 
  68.                 mPopupWindow.dismiss(); 
  69.                 backgroundAlpha(1f); 
  70.             } 
  71.         }); 
  72.         tv_ensure.setOnClickListener(new View.OnClickListener() { 
  73.  
  74.             @Override 
  75.             public void onClick(View arg0) { 
  76.                 beginTime = wheelMainDate.getTime().toString(); 
  77.                 try { 
  78.                     Date begin = dateFormat.parse(currentTime); 
  79.                     Date end = dateFormat.parse(beginTime); 
  80.                     tv_house_time.setText(DateUtils.currentTimeDeatil(begin)); 
  81.                 } catch (ParseException e) { 
  82.                     e.printStackTrace(); 
  83.                 } 
  84.                 mPopupWindow.dismiss(); 
  85.                 backgroundAlpha(1f); 
  86.             } 
  87.         }); 
  88.     } 
  89.  
  90.     public void backgroundAlpha(float bgAlpha) { 
  91.         WindowManager.LayoutParams lp = getWindow().getAttributes(); 
  92.         lp.alpha = bgAlpha; 
  93.         getWindow().setAttributes(lp); 
  94.     } 
  95.  
  96.     @Override 
  97.     public void onClick(View v) { 
  98.         switch (v.getId()){ 
  99.             case R.id.tv_house_time: 
  100.                 showBottoPopupWindow(); 
  101.                 break; 
  102.         } 
  103.     } 
  104.  
  105.     class poponDismissListener implements PopupWindow.OnDismissListener { 
  106.         @Override 
  107.         public void onDismiss() { 
  108.             backgroundAlpha(1f); 
  109.         } 
  110.  
  111.     } 
  112. }  

布局內(nèi)容的

 
 
 
 
  1.     android:id="@+id/rel_select" 
  2.     android:layout_width="wrap_content" 
  3.     android:layout_height="wrap_content" 
  4.     android:layout_centerInParent="true" 
  5.     android:layout_margin="10dp" 
  6.     android:background="@drawable/border_circle_radius" 
  7.     android:orientation="vertical" > 
  8.     android:background="#2F0F9980" 
  9.     android:padding="10dp" 
  10.     android:id="@+id/tv_pop_title" 
  11.     android:textSize="18sp" 
  12.     android:gravity="center" 
  13.     android:textColor="#301616" 
  14.     android:layout_width="match_parent" 
  15.     android:layout_height="wrap_content" /> 
  16.     
  17.         android:id="@+id/timePicker1" 
  18.         android:layout_width="match_parent" 
  19.         android:layout_height="wrap_content" 
  20.         android:orientation="horizontal" > 
  21.         
  22.             android:id="@+id/year" 
  23.             android:layout_width="wrap_content" 
  24.             android:layout_weight="1" 
  25.             android:layout_height="wrap_content" /> 
  26.         
  27.             android:layout_width="1dp" 
  28.             android:gravity="center_vertical" 
  29.             android:layout_gravity="center" 
  30.             android:background="@drawable/dotted_line" 
  31.             android:layout_height="match_parent" /> 
  32.         
  33.             android:id="@+id/month" 
  34.             android:layout_width="wrap_content" 
  35.             android:layout_weight="1" 
  36.             android:layout_height="wrap_content" /> 
  37.         
  38.             android:layout_width="1dp" 
  39.             android:gravity="center_vertical" 
  40.             android:layout_gravity="center" 
  41.             android:background="@drawable/dotted_line" 
  42.             android:layout_height="match_parent" /> 
  43.         
  44.             android:id="@+id/day" 
  45.             android:layout_width="wrap_content" 
  46.             android:layout_weight="1" 
  47.             android:layout_height="wrap_content" /> 
  48.         
  49.             android:layout_width="1dp" 
  50.             android:background="@drawable/dotted_line" 
  51.             android:layout_height="match_parent" /> 
  52.         
  53.             android:id="@+id/hour" 
  54.             android:layout_width="wrap_content" 
  55.             android:layout_weight="1" 
  56.             android:layout_height="wrap_content" /> 
  57.         
  58.             android:layout_width="1dp" 
  59.             android:background="@drawable/dotted_line" 
  60.             android:layout_height="match_parent" /> 
  61.         
  62.             android:id="@+id/mins" 
  63.             android:layout_width="wrap_content" 
  64.             android:layout_weight="1" 
  65.             android:layout_height="wrap_content" /> 
  66.      
  67.     
  68.         android:layout_width="match_parent" 
  69.         android:layout_height="wrap_content" 
  70.         android:background="#2F0F9980" 
  71.         android:padding="10dp" 
  72.         android:orientation="horizontal" > 
  73.  
  74.         
  75.             android:id="@+id/tv_cancle" 
  76.             android:layout_width="0dp" 
  77.             android:layout_height="wrap_content" 
  78.             android:gravity="center" 
  79.             android:paddingLeft="20dp" 
  80.             android:paddingRight="20dp" 
  81.             android:padding="5dp" 
  82.             android:textSize="18sp" 
  83.             android:textColor="#ff0000" 
  84.             android:layout_weight="1" 
  85.             android:background="@drawable/btn_pop" 
  86.             android:text="取消" /> 
  87.  
  88.         
  89.             android:layout_width="0dp" 
  90.             android:layout_height="wrap_content" 
  91.             android:layout_weight="3" /> 
  92.  
  93.         
  94.             android:id="@+id/tv_ensure" 
  95.             android:layout_width="0dp" 
  96.             android:layout_height="wrap_content" 
  97.             android:gravity="center" 
  98.             android:textColor="#414341" 
  99.             android:padding="5dp" 
  100.             android:paddingLeft="20dp" 
  101.             android:paddingRight="20dp" 
  102.             android:layout_weight="1" 
  103.             android:textSize="18sp" 
  104.             android:background="@drawable/btn_pop" 
  105.             android:text="確定" /> 
  106.      
  107.  
  108.   

請(qǐng)注意

MainActivity里面的顯示時(shí)間的 tv_house_time.setText(DateUtils.currentTimeDeatil(begin));需要更改為

tv_house_time.setText(DateUtils.formateStringH(beginTime,DateUtils.yyyyMMddHHmm));否則現(xiàn)實(shí)的額時(shí)間為00:00

修改后的

將WheelMain里面的以下代碼

 
 
 
 
  1. wv_mins.setAdapter(adapter); 
  2. wv_mins.setCyclic(true);// 可循環(huán)滾動(dòng) 
  3. wv_mins.setLabel(“分”);// 添加文字 
  4. int min = setMinute(m); 
  5. wv_mins.setCurrentItem(min);  

更換為

 
 
 
 
  1. wv_mins.setAdapter(new NumericWheelAdapter( 
  2. 0, 59)); 
  3. wv_mins.setCyclic(true);// 可循環(huán)滾動(dòng) 
  4. wv_mins.setLabel(“分”);// 添加文字 
  5. wv_mins.setCurrentItem(m);  

還需要將

 
 
 
 
  1. int minute = Integer.valueOf(adapter.getItem(wv_mins.getCurrentItem())); 

改為

 
 
 
 
  1. int minute = wv_mins.getCurrentItem(); 

會(huì)將分鐘更改為從0到59

如果不想要時(shí)間只想要年月日的話只需要

 
 
 
 
  1. if (hasSelectTime) { 
  2.  
  3. wv_hours.setVisibility(View.GONE); 
  4.  
  5. wv_mins.setVisibility(View.GONE); 
  6.  
  7. } else { 
  8.  
  9. wv_hours.setVisibility(View.GONE); 
  10.  
  11. wv_mins.setVisibility(View.GONE); 
  12.  
  13. wv_day.setVisibility(View.GONE); 
  14.  
  15. }  

將這段代碼放開就可以了還要將以下綠色區(qū)域內(nèi)的代碼去掉

還需要將 MainActivty里的如下代碼

 
 
 
 
  1. wheelMainDate.initDateTimePicker(year, month, day, hours,minute); 

更改為

 
 
 
 
  1. wheelMainDate.initDateTimePicker(year, month, day); 

還有 wheelMain里的

 
 
 
 
  1. if (!hasSelectTime) { 
  2.         sb.append((wv_year.getCurrentItem() + START_YEAR)).append("-") 
  3.                 .append(strMon).append("-") 
  4.                 .append(strDay).append("  ").append(strHour).append(":").append(strMin); 
  5.     }else{ 
  6.         sb.append((wv_year.getCurrentItem() + START_YEAR)).append("-") 
  7.                 .append(strMon).append("-") 
  8.                 .append(strDay).append("  ").append(strHour).append(":").append(strMin); 
  9.     }  

需要修改為

 
 
 
 
  1. if (!hasSelectTime) {      
  2.    sb.append((wv_year.getCurrentItem() + START_YEAR)).append("-") 
  3.                 .append(strMon).append("-") 
  4.                 .append(strDay); 
  5.     }else{ 
  6.         sb.append((wv_year.getCurrentItem() + START_YEAR)).append("-") 
  7.                 .append(strMon).append("-") 
  8.                 .append(strDay); 
  9.     }  

實(shí)現(xiàn)效果如下圖


網(wǎng)站欄目:Android日期時(shí)間選擇器
URL地址:http://www.dlmjj.cn/article/ccspggg.html