
经过源码研究:该结构主要包含三个NumberPicker:
private final NumberPicker mDayPicker;
private final NumberPicker mMonthPicker;
先不显示某个直接显示隐藏
关键步骤获取这几个Picker,因为4.0.1这几个变量的名字发生改变,所以这里通过id去取得
id分别为 com.android.internal.R.id.month,com.android.internal.R.id.year,com.android.internal.R.id.day
见博客com.android.internal.R的值
通过该先获取该datepicker.findViewByid(如上id)
然后.setVisibility(View.GONE);
详见代码:
setContentView(R.layout.main);
int id = 0;
//方式一
// try {
// Class c = Class.forName("com.android.internal.R$id");
// Object obj = c.newInstance();
// Field field = c.getField("month");
// id = field.getInt(obj);
// } catch (Exception e) {
// }
//方式二
Resources mResources = getResources();
id = mResources.getIdentifier("year", "id", "android");
mDatePicker = (DatePicker) findViewById(R.id.datapick);
// 16908723
View view = mDatePicker.findViewById(id);
view.setVisibility(View.GONE);