这种错误就像一个黑魔法:
我正在尝试移植https://github.com/SimonVT/android-timepicker以完成 Holo 样式(默认情况下,它只有 ICS timepicker 小部件,对话框仍然是 pre-Honeycomb)。
我使用 timepicker 的特殊属性扩展了 Theme.Sherlock,然后将其应用于整个应用程序。对话框看起来和默认的一样(上面提到过)。之后,我刚刚将 HoloEverywhere 库添加到项目中......黑色魔法出现了!Timepicker 小部件以某种方式丢失了一些视图,例如蓝线并更改了对话框中的位置。我仍然想知道这个故障的原因。
注意:在我的项目(代码)以及 TimePicker lib 中,我对 HoloEverywhere 一无所知
注意:我还更改了 timepicker 中的一些属性,因为它们与 HoloEverywhere 的属性冲突(因为“...属性已被声明”错误)
代码:
public class DialogSample extends SherlockFragmentActivity implements OnTimeSetListener {
private TextView mTimeDisplay;
private int mHour;
private int mMinute;
static final int TIME_DIALOG_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
mTimeDisplay = (TextView) findViewById(R.id.timeDisplay);
findViewById(R.id.btnDialog).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getSupportFragmentManager(), "timePicker");
}
});
updateDisplay();
}
// updates the time we display in the TextView
private void updateDisplay() {
mTimeDisplay.setText(
new StringBuilder()
.append(pad(mHour)).append(":")
.append(pad(mMinute)));
}
private static String pad(int c) {
if (c >= 10) {
return String.valueOf(c);
} else {
return "0" + String.valueOf(c);
}
}
static public class TimePickerFragment extends SherlockDialogFragment {
@Override
public TimePickerDialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
return new TimePickerDialog(getSherlockActivity(), (DialogSample)getSherlockActivity(), hour, minute, true);
}
public TimePickerFragment() {
}
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mHour = hourOfDay;
mMinute = minute;
updateDisplay();
}
}