如何在活动中显示像片段一样的对话框

时间:2014-09-10 07:19:39

标签: android android-fragments datepicker

我想显示日期Dialog Picker Like This Image enter image description here

我可以使用代码帮助打开对话框但看起来像旧版本的Datepicker

我想要datepicker像我发布的图像

这是My DateDilogefragment.java

public class DateDialogFragment extends SherlockDialogFragment {    

public static String TAG = "DateDialogFragment";
static Context mContext; 
static int mYear;
static int mMonth;
static int mDay;
static DateDialogFragmentListener mListener;


public static DateDialogFragment newInstance(Context context, DateDialogFragmentListener listener, Calendar now) {
    DateDialogFragment dialog = new DateDialogFragment();
    mContext = context;
    mListener = listener;       
    mYear = now.get(Calendar.YEAR);
    mMonth = now.get(Calendar.MONTH);
    mDay = now.get(Calendar.DAY_OF_MONTH);      
    return dialog;
}


public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new DatePickerDialog(mContext, mDateSetListener, mYear, mMonth, mDay);
}


private OnDateSetListener mDateSetListener = new OnDateSetListener() {      
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        mYear = year;
        mMonth = monthOfYear;
        mDay = dayOfMonth;          
        mListener.updateChangedDate(year, monthOfYear, dayOfMonth);
    }


};


public interface DateDialogFragmentListener {
    public void updateChangedDate(int year, int month, int day);
}

}

和我的活动类

        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                showDatePickerDialog();
            }
        });



    }



    public void showDatePickerDialog() {
        // TODO Auto-generated method stub
         now = Calendar.getInstance();   
        DateDialogFragment frag = DateDialogFragment.newInstance(
                this, new DateDialogFragment.DateDialogFragmentListener() {
            public void updateChangedDate(int year, int month, int day) {
               tv.setText(String.valueOf(day) + "-" + String.valueOf(month+1) + "-" +  String.valueOf(year));                               
                now.set(year, month, day);
              //pet.setBirthdate(birthdate.getText().toString());
            }
        }, 
        now);
        FragmentManager fm =  getSupportFragmentManager();
        frag.show(fm, "DateDialogFragment");   
    }
}

你可以告诉我做错了什么..为什么我的对话框像旧版一样打开?

我的开放就像 enter image description here

而不是ku

2 个答案:

答案 0 :(得分:0)

更改您的应用主题:

 <style name="AppTheme" parent="android:Theme.Holo.Light">
       <item name="android:windowNoTitle">true</item>
 </style>

这应该可以解决您的问题。

答案 1 :(得分:0)

此日期选择器位于旧设备中,新的API级别提供Light Theme。你的主题是深黑色。如果您将在API大于14的设备中运行您的APP(可能是在Honeycomb中实现)。 所以将你的风格改为Theme.Light。您可以在“值”文件夹中查看您的样式。