我有这个奇怪的错误,我弹出对话框要求用户在 tabview 中输入日期和时间。日期选择器工作正常,但时间选择器在白色背景上显示白色文本,几乎不可见。
这是我的标签视图代码。
TabHost tabHost = (TabHost) timerDialog.findViewById(android.R.id.tabhost);
tabHost.setup();
final TabWidget tabWidget = tabHost.getTabWidget();
final FrameLayout tabContent = tabHost.getTabContentView();
TextView[] originalTextViews = new TextView[tabWidget.getTabCount()];
for (int index = 0; index < tabWidget.getTabCount(); index++)
{
originalTextViews[index] = (TextView) tabWidget.getChildTabViewAt(index);
}
tabWidget.removeAllViews();
for (int index = 0; index < tabContent.getChildCount(); index++)
{
tabContent.getChildAt(index).setVisibility(View.GONE);
}
for (int index = 0; index < originalTextViews.length; index++)
{
final TextView tabWidgetTextView = originalTextViews[index];
final View tabContentView = tabContent.getChildAt(index);
TabSpec tabSpec = tabHost.newTabSpec((String) tabWidgetTextView.getTag());
tabSpec.setContent(new TabContentFactory()
{
@Override
public View createTabContent(String tag)
{
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
((TimePicker)tabContentView).setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
((TimePicker)tabContentView).setCurrentMinute(c.get(Calendar.MINUTE));
return tabContentView;
}
});
if (tabWidgetTextView.getBackground() == null)
{
tabSpec.setIndicator(tabWidgetTextView.getText());
}
else
{
tabSpec.setIndicator(tabWidgetTextView.getText(), tabWidgetTextView.getBackground());
}
tabHost.addTab(tabSpec);
}
AlertDialog timer = timerAlert.create();
timer.show();
timer.setOnDismissListener(new OnDismissListener()
{
@Override
public void onDismiss(DialogInterface arg0)
{
if(isSaveClicked)
{
TimePicker startTime = (TimePicker) timerDialog.findViewById(R.id.startTimePicker);
TimePicker endTime = (TimePicker) timerDialog.findViewById(R.id.endTimePicker);
int eHour = endTime.getCurrentHour();
int eMinute = endTime.getCurrentMinute();
int sHour = startTime.getCurrentHour();
int sMinute = startTime.getCurrentMinute();
Calendar startCal = Calendar.getInstance();
Calendar endCal = Calendar.getInstance();
startCal.set(Calendar.HOUR_OF_DAY, sHour);
startCal.set(Calendar.MINUTE, sMinute);
endCal.set(Calendar.HOUR_OF_DAY, eHour);
endCal.set(Calendar.MINUTE, eMinute);
Log.d("silencer","start"+startCal.getTimeInMillis()+" end "+endCal.getTimeInMillis());
if(startCal.getTimeInMillis()>endCal.getTimeInMillis()||startCal.getTimeInMillis()==endCal.getTimeInMillis())
{
Toast.makeText(MainActivity.this, "Start time must be less then end time.", Toast.LENGTH_LONG).show();
}
else
ba.updateOrInsertSilence(startCal.getTimeInMillis(), endCal.getTimeInMillis(), MainActivity.this,1);
}
}
});
和 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:tag="Start"
android:text="Start Time"
android:textColor="@color/blue"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
<TextView
android:tag="End"
android:text="End Time"
android:textColor="@color/blue"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TimePicker
android:id="@+id/startTimePicker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@android:style/Theme.Light"/>
<TimePicker
android:id="@+id/endTimePicker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@android:style/Theme.Light"/>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
关于如何将颜色设置为黑色的任何想法?