您好我正在处理有标签的应用程序。我使用片段标签主机创建了标签。我添加了一个9补丁图像作为选项卡的背景。整个应用程序在ICS上工作正常,但是当我在软糖上测试时,它会显示带有默认背景图像的标签,当我更改标签时,它会显示正确分配的背景图像。此外,当我导航到其他片段并再次出现时,同样的事情正在发生。 请有人告诉我为什么会这样,我该如何解决? 提前谢谢。
下面是我正在使用的代码: -
public class FragmentMain extends Fragment implements OnClickListener, OnTabChangeListener
{
FragmentTabHost mTabHost;
Button BTN_Email;
View content;
@SuppressLint("NewApi")
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
mTabHost.setOnTabChangedListener(this);
mTabHost.getTabWidget().setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
mTabHost.getTabWidget().setCurrentTab(0);
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.segment_radio_grey_left_press);
for (int tabIndex = 0 ; tabIndex < mTabHost.getTabWidget().getTabCount() ; tabIndex ++) {
View tab = mTabHost.getTabWidget().getChildTabViewAt(tabIndex);
TextView t = (TextView)tab.findViewById(android.R.id.title);
t.setTextColor(getResources().getColor(R.color.White));
}
}
@Override
public void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
// TODO Auto-generated method stub
View v = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_charts,
null);
BTN_Email = (Button) v.findViewById(R.id.BTN_email);
BTN_Email.setOnClickListener(onEmailClick);
content = v.findViewById(R.id.main);
content.setDrawingCacheEnabled(true);
mTabHost = (FragmentTabHost) v.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.tabcontent);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("One"), Chart_One.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Two"), Chart_Two.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Three"), Chart_Threer.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab4").setIndicator("Four"), Chart_Four.class, null);
for(int i = 0; i<mTabHost.getTabWidget().getChildCount(); i++)
{
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.segment_radio_grey_left);
mTabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.segment_radio_grey_middle);
mTabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.segment_radio_grey_middle);
mTabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.segment_radio_grey_right);
// mTabHost.getTabWidget().getChildAt(i).setBackgroundColor(getResources().getColor(R.color.BlueKoi));
}
return v;
}
// Manages the Tab changes, synchronizing it with Pages
public void onTabChanged(String tag) {
int pos = this.mTabHost.getCurrentTab();
if(pos == 1)
{
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.segment_radio_grey_left);
mTabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.segment_radio_grey_middle_press);
mTabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.segment_radio_grey_middle);
mTabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.segment_radio_grey_right);
}
else if(pos == 2)
{
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.segment_radio_grey_left);
mTabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.segment_radio_grey_middle);
mTabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.segment_radio_grey_middle_press);
mTabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.segment_radio_grey_right);
}
else if(pos == 3)
{
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.segment_radio_grey_left);
mTabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.segment_radio_grey_middle);
mTabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.segment_radio_grey_middle);
mTabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.segment_radio_grey_right_press);
}
else if(pos == 0)
{
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.segment_radio_grey_left_press);
mTabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.segment_radio_grey_middle);
mTabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.segment_radio_grey_middle);
mTabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.segment_radio_grey_right);
}
this.mTabHost.setCurrentTab(pos);
for (int tabIndex = 0 ; tabIndex < mTabHost.getTabWidget().getTabCount() ; tabIndex ++) {
View tab = mTabHost.getTabWidget().getChildTabViewAt(tabIndex);
TextView t = (TextView)tab.findViewById(android.R.id.title);
t.setTextColor(getResources().getColor(R.color.White));
}
}
}