Android Material Design 5.0 PickerDialog

來源:互聯網
上載者:User

Android Material Design 5.0 PickerDialog

5.0系統下的時間選取器:

 

該項目相容到3.0以下所以用第三方開源項目:actionbarsherlock,動畫效果相容:nineoldandroids-2.4.0.jar,格式轉換器:joda-time-2.1.jar

主要調用代碼執行個體:

 

import org.joda.time.DateTime;import android.os.Bundle;import android.support.v4.app.FragmentTransaction;import android.text.format.DateFormat;import android.widget.Toast;import com.actionbarsherlock.app.SherlockFragmentActivity;import com.doomonafireball.betterpickers.calendardatepicker.CalendarDatePickerDialog;import com.doomonafireball.betterpickers.radialtimepicker.RadialTimePickerDialog;public class MainActivity extends SherlockFragmentActivity implements CalendarDatePickerDialog.OnDateSetListener, RadialTimePickerDialog.OnTimeSetListener {public static final String FRAG_TAG_TIME_PICKER = timePickerDialogFragment;public static final String FRAG_TAG_DATE_PICKER = fragment_date_picker_name;private boolean mHasDialogFrame;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);/*FragmentManager fm = getSupportFragmentManager();DateTime now = DateTime.now();CalendarDatePickerDialog calendarDatePickerDialog = CalendarDatePickerDialog.newInstance(this, now.getYear(), now.getMonthOfYear() - 1,now.getDayOfMonth());calendarDatePickerDialog.show(fm, FRAG_TAG_DATE_PICKER);*/ if (savedInstanceState == null) {            mHasDialogFrame = findViewById(R.id.frame) != null;        }DateTime now = DateTime.now();RadialTimePickerDialog timePickerDialog = RadialTimePickerDialog.newInstance(this, now.getHourOfDay(), now.getMinuteOfHour(),DateFormat.is24HourFormat(this));if (mHasDialogFrame) {FragmentTransaction ft = getSupportFragmentManager().beginTransaction();ft.add(R.id.frame, timePickerDialog, FRAG_TAG_TIME_PICKER).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();} else {timePickerDialog.show(getSupportFragmentManager(), FRAG_TAG_TIME_PICKER);}}@Overridepublic void onResume() {// Example of reattaching to the fragmentsuper.onResume();/*CalendarDatePickerDialog calendarDatePickerDialog = (CalendarDatePickerDialog) getSupportFragmentManager().findFragmentByTag(FRAG_TAG_DATE_PICKER);if (calendarDatePickerDialog != null) {calendarDatePickerDialog.setOnDateSetListener(this);}*/ RadialTimePickerDialog rtpd = (RadialTimePickerDialog) getSupportFragmentManager().findFragmentByTag(                FRAG_TAG_TIME_PICKER);        if (rtpd != null) {            rtpd.setOnTimeSetListener(this);        }}@Overridepublic void onTimeSet(RadialTimePickerDialog dialog, int hourOfDay,int minute) {// TODO Auto-generated method stubString result= + hourOfDay + : + minute;Toast.makeText(this, result, Toast.LENGTH_SHORT).show();}@Overridepublic void onDateSet(CalendarDatePickerDialog dialog, int year,int monthOfYear, int dayOfMonth) {// TODO Auto-generated method stubString result=Year:  + year + Month:  + monthOfYear + Day:  + dayOfMonth;Toast.makeText(this, result, Toast.LENGTH_SHORT).show();}}

Theme:

 

 



介面顏色風格修改:

 

 

    #00000000    #ffffffff    #ff4c4c4c    #28ffffff    #00000000    #46c5c1ff    #ff33b5e5    #ff000000    #ffb2b2b2    #28000000    #00000000    #ff00ddff    #ff00ddff    #ffffff    #f2f2f2    #cccccc    #8c8c8c    #000000    #cccccc    #8c8c8c    #7f000000    #33b5e5    #c1e8f7    #33999999    #0099cc    #ff999999    #999999    #f2f2f2    #ffd1d2d4        #ff3333    #853333    #404040    #363636    #808080    #ffffff    #888888    #bfbfbf    #fff2f2f2    #ff737373

比如:

 

 

  #cfcfcf

修改星期幾對應的TextView 的背景色,具體顏色含義參考 Dialog定義

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.