Android 在对话框片段中放置选项卡
我试图将TabHost放在DialogFragment中,但目前它不起作用,并在第行返回null:Android 在对话框片段中放置选项卡,android,android-tabhost,android-dialogfragment,Android,Android Tabhost,Android Dialogfragment,我试图将TabHost放在DialogFragment中,但目前它不起作用,并在第行返回null: tabs.findviewbyd(R.id.tabHost) 如何在DialogFragment中初始化tabhost以允许选项卡显示 选项卡式对话框日志类: public class InviteFriendTabbedAlertDialog extends DialogFragment { TabHost tabs; @Override public View on
tabs.findviewbyd(R.id.tabHost)代码>
如何在DialogFragment中初始化tabhost以允许选项卡显示
选项卡式对话框日志类:
public class InviteFriendTabbedAlertDialog extends DialogFragment {
TabHost tabs;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//return inflater.inflate(R.layout.invite_friend_tabbed_dialog, null);
// Add tabs
tabs.findViewById(R.id.tabHost);
tabs.setup();
TabHost.TabSpec tabpage1 = tabs.newTabSpec("one");
tabpage1.setContent(R.id.shareIndividual);
tabpage1.setIndicator("Tab 1", getResources().getDrawable(R.drawable.abc_ab_solid_dark_holo));
TabHost.TabSpec tabpage2 = tabs.newTabSpec("two");
tabpage2.setContent(R.id.shareGroup);
tabpage2.setIndicator("Tab 2", getResources().getDrawable(R.drawable.abc_ab_bottom_transparent_light_holo));
tabs.addTab(tabpage1);
tabs.addTab(tabpage2);
return inflater.inflate(R.layout.invite_friend_tabbed_dialog, null);
}
}
选项卡式布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TabHost
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabHost"
android:layout_gravity="center_horizontal">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/shareIndividual"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:id="@+id/shareGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
初始化选项卡
,并使用膨胀视图,在该视图中使用带有TabHost
的TabHost来初始化选项卡
变量:
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.invite_friend_tabbed_dialog, null);
// Add tabs
tabs=(TabHost)view.findViewById(R.id.tabHost);
//...your code here
return view;
}
首先充气布局,然后正确初始化tabhost