Android JellyBean DatePicker问题

时间:2012-12-15 23:21:41

标签: android

我在Android Activity中使用了DatePicker。我只需要向用户显示年份。我用

private void findAndHideField(DatePicker datepicker, String name) {
        try {
            Field field = DatePicker.class.getDeclaredField(name);
            field.setAccessible(true);
            View fieldInstance = (View) field.get(datepicker);
            fieldInstance.setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

然后

        findAndHideField(startDatePicker, "mDayPicker");
        findAndHideField(startDatePicker, "mMonthPicker");
        findAndHideField(startDatePicker, "mDaySpinner");
        findAndHideField(startDatePicker, "mMonthSpinner");

代码在2.3.x上工作正常,但在4.1.x手机上,这只显示一个完整的日历。我该怎么办才能使年份表盘可见?

1 个答案:

答案 0 :(得分:2)

在XML中添加这些行

android:calendarViewShown="false"

DatePicker