Android 在TabHost中始终选择Tab
我的TabHost有一个问题,在一个片段中,要选择的第一个选项卡将始终高亮显示,因此我经常选择两个选项卡,如图所示 此处不应突出显示通知强> 但问题仅限于通知选项卡,正如您在这里看到的,朋友选项卡的行为正常,因为它是第二个添加的 这是我保存TabHost的片段的代码Android 在TabHost中始终选择Tab,android,android-fragments,android-tabhost,fragment-tab-host,Android,Android Fragments,Android Tabhost,Fragment Tab Host,我的TabHost有一个问题,在一个片段中,要选择的第一个选项卡将始终高亮显示,因此我经常选择两个选项卡,如图所示 此处不应突出显示通知 但问题仅限于通知选项卡,正如您在这里看到的,朋友选项卡的行为正常,因为它是第二个添加的 这是我保存TabHost的片段的代码 public class ProfileContentFragment extends Fragment { private FragmentTabHost mTabHost; public ProfileContentFragme
public class ProfileContentFragment extends Fragment {
private FragmentTabHost mTabHost;
public ProfileContentFragment() {
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.profile_content_fragment,container, false);
mTabHost = (FragmentTabHost) rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getFragmentManager(), android.R.id.tabcontent);
mTabHost.addTab(mTabHost.newTabSpec("notifications").setIndicator("Notifications "),
NotificationsFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("friends").setIndicator("Friends"),
FriendsFragment.class, null);
return rootView;
}
@Override
public void onDestroyView(){
super.onDestroyView();;
mTabHost=null;
}
}
这是XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/LinearLayout01"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</FrameLayout>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</RelativeLayout>
已解决: 这是通过改变来解决的
mTabHost.setup(getActivity(), getFragmentManager(), android.R.id.tabcontent);
致:
mTabHost.setup(getActivity(),getChildFragmentManager(),android.R.id.tabcontent)代码>已解决:
这是通过改变来解决的
mTabHost.setup(getActivity(), getFragmentManager(), android.R.id.tabcontent);
致:
mTabHost.setup(getActivity(),getChildFragmentManager(),android.R.id.tabcontent)代码>如果您解决了自己的问题,请发布答案,并接受答案,而不是编辑问题。如果您解决了自己的问题,请发布答案,并接受答案,而不是编辑问题。