欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

android自定義控件或?qū)傩?日期時(shí)間選擇框

系統(tǒng) 2200 0

關(guān)于自定義控件或?qū)傩?
請(qǐng)轉(zhuǎn)此學(xué)習(xí) ?
看代碼之前先看看效果圖?
時(shí)間選擇?
android自定義控件或?qū)傩?日期時(shí)間選擇框 ?
使用方法:配置為時(shí)間(dateTime:dateFormatStr="HH:mm:ss" dateTime:dateFormat="time")?
Xml代碼?? 收藏代碼
  1. <? xml ? version = "1.0" ? encoding = "UTF-8" ?> ??
  2. < LinearLayout ? xmlns:android = "http://schemas.android.com/apk/res/android" ??
  3. ???????? xmlns:dateTime = "http://schemas.android.com/apk/res/com.app" /> ??
  4. ??
  5. ? < com.app.view.DatePickText ?? android:layout_marginLeft = "7dp" ??? android:layout_width = "230dp" ? android:layout_height = "35dp" ???
  6. ????????? android:id = "@+id/v_birthday" ? dateTime:dateFormatStr = "HH:mm:ss" ? dateTime:dateFormat = "time" /> ??

看代碼之前先看看效果圖?

日期選擇?
android自定義控件或?qū)傩?日期時(shí)間選擇框 ?
使用方法:配置為日期(dateTime:dateFormatStr="yyyy-MM-dd" dateTime:dateFormat="date")?
Xml代碼?? 收藏代碼
  1. <? xml ? version = "1.0" ? encoding = "UTF-8" ?> ??
  2. < LinearLayout ? xmlns:android = "http://schemas.android.com/apk/res/android" ??
  3. ???????? xmlns:dateTime = "http://schemas.android.com/apk/res/com.app" /> ??
  4. ??
  5. ? < com.app.view.DatePickText ?? android:layout_marginLeft = "7dp" ??? android:layout_width = "230dp" ? android:layout_height = "35dp" ???
  6. ????????? android:id = "@+id/v_birthday" ? dateTime:dateFormatStr = "yyyy-MM-dd" ? dateTime:dateFormat = "date" /> ??

res/values/attrs.xml?
Xml代碼?? 收藏代碼
  1. <? xml ? version = "1.0" ? encoding = "utf-8" ?> ??
  2. < resources > ??
  3. ???? < declare-styleable ? name = "DatePickText" > ????
  4. ?????????
  5. ???????? < attr ? name = "dateFormatStr" ? format = "string" /> ??
  6. ???????? < attr ? name = "dateFormat" ? > ???
  7. ?????????????? <!--?yyyy-MM-dd??--> ???
  8. ????????????? < enum ? name = "date" ? value = "0" ? /> ??
  9. ????????????? <!--?HH:mm:ss?--> ??
  10. ????????????? < enum ? name = "time" ? value = "1" ? /> ??
  11. ????????? </ attr > ??
  12. ????????
  13. ???? </ declare-styleable > ????
  14. </ resources > ??

實(shí)現(xiàn)類(lèi)?
Java代碼?? 收藏代碼
  1. package ?com.app.view;??
  2. ??
  3. import ?java.text.SimpleDateFormat;??
  4. import ?java.util.Calendar;??
  5. import ?java.util.Locale;??
  6. ??
  7. import ?android.app.DatePickerDialog;??
  8. import ?android.app.TimePickerDialog;??
  9. import ?android.content.Context;??
  10. import ?android.content.res.TypedArray;??
  11. import ?android.util.AttributeSet;??
  12. import ?android.view.LayoutInflater;??
  13. import ?android.view.View;??
  14. import ?android.widget.DatePicker;??
  15. import ?android.widget.EditText;??
  16. import ?android.widget.ImageButton;??
  17. import ?android.widget.LinearLayout;??
  18. import ?android.widget.TimePicker;??
  19. ??
  20. import ?com.app.R;??
  21. ??
  22. public ? class ?DatePickText? extends ?LinearLayout?{??
  23. ??
  24. ??? private ?Integer?dateFormat;??
  25. ??? private ?String?layout_height,layout_width;??
  26. ??? private ?String?dateFormatStr;??
  27. ??? private ?EditText?edit;??
  28. ??? private ?ImageButton?btn_date;??
  29. ??? private ?LinearLayout?layout;??
  30. ???? public ? static ? final ? int ?TOP?=? 0 ;??
  31. ???? public ? static ? final ? int ?BOTTOM?=? 1 ;??
  32. ???? public ? static ? final ? int ?LEFT?=? 2 ;??
  33. ???? public ? static ? final ? int ?RIGHT?=? 3 ;??
  34. ??????
  35. ???? public ? static ? final ? int ?DATE?=? 0 ;??
  36. ???? public ? static ? final ? int ?TIME?=? 1 ;??
  37. ???? private ?SimpleDateFormat?df?;??
  38. ???? private ? final ?Calendar?cal?=?Calendar.getInstance(Locale.SIMPLIFIED_CHINESE);??
  39. ??????
  40. ???? public ?DatePickText(Context?context)?{??
  41. ???????? super (context);??
  42. ??????????
  43. ????}??
  44. ??
  45. ??????
  46. ??
  47. ???? public ?DatePickText(Context?context,?AttributeSet?attrs)?{??
  48. ???????? super (context,?attrs);??
  49. ??????????
  50. ????????TypedArray?typeA?=context.obtainStyledAttributes(attrs,?R.styleable.DatePickText);??
  51. ??????????
  52. ????????layout_height=typeA.getString(R.styleable.DatePickText_layout_height);??
  53. ????????layout_width=typeA.getString(R.styleable.DatePickText_layout_width);??
  54. ?????????dateFormatStr=typeA.getString(R.styleable.DatePickText_dateFormatStr);??
  55. ?????????dateFormat=typeA.getInteger(R.styleable.DatePickText_dateFormat,DATE);??
  56. ???????? //typeA.g ??
  57. ???????????
  58. ?????LayoutInflater?layoutInflater?=?(LayoutInflater)?context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);??
  59. ?????layoutInflater.inflate(R.layout.date_pick_txt, this );??
  60. ?????layout=(LinearLayout)findViewById(R.id.date_linear);??
  61. ?????edit=(EditText)findViewById(R.id.date_txt);??
  62. ?????btn_date=(ImageButton)findViewById(R.id.date_btn);??
  63. ???????
  64. ?????processUi(context);??
  65. ????}??
  66. ?????
  67. ???? private ? void ?processUi( final ?Context?context){??
  68. ???????? //ViewGroup.LayoutParams?params=new?ViewGroup.LayoutParams(params); ??
  69. ???????? //layout.setLayoutParams(params); ??
  70. ??????????
  71. ????????btn_date.setOnClickListener( new ?OnClickListener(){??
  72. ???????????
  73. ???????????? @Override ??
  74. ???????????? public ? void ?onClick(View?v)?{??
  75. ????????????????System.out.println( "-------------click------------" );??
  76. ????????????????buildDateOrTimeDialog(context);??
  77. ??????????????????
  78. ????????????}??
  79. ??????????????
  80. ????????});??
  81. ??????????
  82. ????}??
  83. ???? private ? void ?buildDateOrTimeDialog(Context?context){??
  84. ????????df?=? new ?SimpleDateFormat(dateFormatStr);??
  85. ??????????
  86. ???????? switch (dateFormat)??
  87. ????????{??
  88. ???????? case ?DATE:??
  89. ?????????????date:??
  90. ???????????????? new ?DatePickerDialog(?context,listener?,??
  91. ????????????????????cal?.get(Calendar.?YEAR?),??
  92. ???????????????????????
  93. ????????????????????cal?.get(Calendar.?MONTH?),??
  94. ???????????????????????
  95. ????????????????????cal?.get(Calendar.?DAY_OF_MONTH?)??
  96. ???????????????????????
  97. ????????????????????).show();??
  98. ???????????? break ;??
  99. ???????????????????????
  100. ???????? case ?TIME:??
  101. ????????????System.out.println( "----------time---------------" );??
  102. ????????????? new ?TimePickerDialog(context,timeListen,cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE), true ).show();??
  103. ????????????? break ;??
  104. ???????? default :??
  105. ???????????? new ?DatePickerDialog(?context,listener?,??
  106. ????????????????????cal?.get(Calendar.?YEAR?),??
  107. ???????????????????????
  108. ????????????????????cal?.get(Calendar.?MONTH?),??
  109. ???????????????????????
  110. ????????????????????cal?.get(Calendar.?DAY_OF_MONTH?)??
  111. ???????????????????????
  112. ????????????????????).show();??
  113. ??????????????
  114. ????????}??
  115. ??????
  116. }??
  117. ??????????
  118. ??????
  119. private ?DatePickerDialog.OnDateSetListener?listener?=? new ?DatePickerDialog.OnDateSetListener(){?? // ??
  120. ???????
  121. ???? @Override ??
  122. ???????
  123. ???? public ? void ?onDateSet(DatePicker?arg0,? int ?arg1,? int ?arg2,? int ?arg3)?{??
  124. ???????
  125. ????cal?.set(Calendar.?YEAR?,?arg1);??
  126. ???????
  127. ????cal?.set(Calendar.?MONTH?,?arg2);??
  128. ???????
  129. ????cal?.set(Calendar.?DAY_OF_MONTH?,?arg3);??
  130. ???????
  131. ????updateDate();??
  132. ???????
  133. ????}??
  134. ???????
  135. ????};??
  136. ??????
  137. ???? //?當(dāng)?DatePickerDialog?關(guān)閉,更新日期顯示 ??
  138. ???????
  139. ???? private ? void ?updateDate(){??
  140. ???????
  141. ??????????edit.setText(?df?.format(?cal?.getTime()));??
  142. ???????
  143. ????}??
  144. ??????
  145. ????TimePickerDialog.OnTimeSetListener?timeListen?=? new ?TimePickerDialog.OnTimeSetListener()?{??
  146. ??
  147. ???????? //同DatePickerDialog控件 ??
  148. ??
  149. ???????? @Override ??
  150. ???????? public ? void ?onTimeSet(TimePicker?view,? int ?hourOfDay,? int ?minute)?{??
  151. ????????????cal.set(Calendar.HOUR_OF_DAY,?hourOfDay);??
  152. ????????????cal.set(Calendar.MINUTE,?minute);??
  153. ????????????cal.set(Calendar.SECOND,?cal.get(Calendar.SECOND));??
  154. ??????????updateTimes();??
  155. ????????}??
  156. ??
  157. ??????
  158. ??
  159. ????????};??
  160. ??????????
  161. ???????? //更新頁(yè)面TextView的方法 ??
  162. ???? private ? void ?updateTimes()?{??
  163. ??????
  164. ????????????edit.setText(df.format(cal.getTime()));??
  165. ????}??
  166. }??

實(shí)現(xiàn)類(lèi)中用到的布局文件?
date_pick_txt.xml?
Xml代碼?? 收藏代碼
  1. <? xml ? version = "1.0" ? encoding = "utf-8" ?> ??
  2. < LinearLayout ??
  3. ?? xmlns:android = "http://schemas.android.com/apk/res/android" ??
  4. ?? android:orientation = "horizontal" ? android:id = "@+id/date_linear" ??
  5. ?? android:layout_width = "230dp" ??
  6. ?? android:layout_height = "35dp" > ??
  7. ??? < RelativeLayout ? android:id = "@+id/date_relative" ? android:layout_height = "fill_parent" ? android:layout_width = "fill_parent" > ??
  8. ??????? < EditText ?? android:id = "@+id/date_txt" ? android:editable = "false" ? android:layout_height = "fill_parent" ? android:layout_width = "fill_parent" ??
  9. ????????????? android:includeFontPadding = "false" ? android:hint = "yyyy-mm-dd" /> ??
  10. ????????????? < ImageButton ? android:src = "@drawable/date_pic" ? android:layout_width = "28dp" ? android:layout_marginLeft = "-33dp" ???
  11. ???????????? android:layout_alignBottom = "@+id/date_txt" ??? android:layout_centerInParent = "true" ? android:layout_centerHorizontal = "true" ??
  12. ?????????? android:layout_height = "26dp" ? android:layout_toRightOf = "@+id/date_txt" ? android:id = "@+id/date_btn" /> /??
  13. ?????????
  14. ???? </ RelativeLayout > ??
  15. ???
  16. ??????
  17. </ LinearLayout > ??

android自定義控件或?qū)傩?日期時(shí)間選擇框


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 一级特黄aaa免费 | 欧美激情久久久久久久久 | 黄a在线 | 深夜寂寞影院 | 爱操影视| 泰国一级毛片aaa下面毛多 | 久久香蕉国产线看观看网站 | 国产欧美性综合视频性刺激 | 欧洲精品色 | 国产精品久久影院 | 国产欧美精品亚洲桃花岛 | 色噜噜视频 | 奇米影视77| 视频二区| 亚洲欧美日韩在线一区二区三区 | 一区二区三区视频免费 | 国产精品美女一区二区三区 | av影音资源 | 91免费视频 | 国产网站免费视频 | 亚洲香蕉视频 | 超碰在线国产 | 国产福利观看 | 欧美在线观看视频一区 | 康熙大帝1994蔺达诺版 | 日韩午夜三级 | 91网站免费观看 | 很黄很色又爽很黄很色又爽 | 欧美的| 久久99精品久久久久久琪琪 | 国产精品无码永久免费888 | 全色网站 | 一97日本道伊人久久综合影院 | 欧美精品一区二区三区在线 | 欧美极品brazzers 高清 | 在线不卡视频 | 欧美午夜不卡 | av国产精品 | 天天操天天插天天干 | 国产成人综合久久 | 国产精品v在线播放观看 |