Android 滑动抽屉内的安卓标签
我想在android中创建一个包含选项卡的导航抽屉,但我什么都做不了。我想将标签(类别、收藏夹)添加到导航抽屉。可以吗 (例如,ios) 我无法在选项卡之间切换。我不能在标签内容上使用任何小部件。(列表视图、按钮等) (编辑:解决方案) (线性布局:滑块菜单布局)Android 滑动抽屉内的安卓标签,android,menu,tabs,navigation-drawer,slidingdrawer,Android,Menu,Tabs,Navigation Drawer,Slidingdrawer,我想在android中创建一个包含选项卡的导航抽屉,但我什么都做不了。我想将标签(类别、收藏夹)添加到导航抽屉。可以吗 (例如,ios) 我无法在选项卡之间切换。我不能在标签内容上使用任何小部件。(列表视图、按钮等) (编辑:解决方案) (线性布局:滑块菜单布局) 我昨天才做的 这是我的抽屉主要活动布局: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:a
我昨天才做的 这是我的抽屉主要活动布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Main layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_background"
android:orientation="vertical" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/layout_location_spinners_campaigns" />
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/layout_campaignslistview" />
</LinearLayout>
<!-- Slider menu -->
<LinearLayout
android:id="@+id/preferencesDrawer"
android:layout_width="290dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/app_background"
android:orientation="vertical" >
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<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"
android:layout_weight="0"
android:orientation="horizontal" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
除此之外,您还需要代码来显示抽屉和自定义选项卡
编辑: 我使用此方法初始化抽屉(在onCreate时调用):
我不明白你为什么不能。抽屉布局只能包含一个成员,但该成员可以是框架布局或线性布局,在抽屉的前两个条目中包含选项卡和搜索元素。@JaySnayder我只能使用“getTabHost().setCurrentTab(2);”在选项卡之间切换,而不使用侦听器。抽屉视图不响应任何运动。有此代码的链接,实际上我尝试了很多,但没有得到任何解决方案,所以如果你有链接,请与我分享,或者codehi@juanjo vega,实际上我做了我想要的。但是我不能在标签之间切换。我试过了所有的听众,我用抽屉里剩下的代码编辑了我的答案。希望这有助于删除此代码的链接,实际上我尝试了很多,但我没有得到任何解决方案,所以如果你有链接,请与我分享,或代码
linearLayout.bringToFront();
linearLayout.requestLayout();
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Main layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_background"
android:orientation="vertical" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/layout_location_spinners_campaigns" />
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/layout_campaignslistview" />
</LinearLayout>
<!-- Slider menu -->
<LinearLayout
android:id="@+id/preferencesDrawer"
android:layout_width="290dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/app_background"
android:orientation="vertical" >
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<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"
android:layout_weight="0"
android:orientation="horizontal" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
FragmentTabHost tabhost;
void buildTabs() {
tabhost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
tabhost.addTab(tabhost.newTabSpec("locations").setIndicator(getString(R.string.locations)), FragmentPreferencesLocations.class, null);
tabhost.addTab(tabhost.newTabSpec("categories").setIndicator(getString(R.string.categories)),FragmentPreferencesCategories.class, null);
}
ActionBarDrawerToggle drawerToggle;
LinearLayout preferencesDrawer;
FragmentTabHost tabhost;
...
void initDrawer() {
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_launcher, R.string.app_name,
R.string.app_name) {
public void onDrawerClosed(View drawerView) {
getSupportActionBar().setTitle(getString(R.string.app_name));
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
drawerClosed(drawerView);
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(getString(R.string.preferences));
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
drawerLayout.setDrawerListener(drawerToggle);
}
// Invoked by action bar button
void clickFilterCategories() {
toggleDrawer(preferencesDrawer);
}
void toggleDrawer(View drawer) {
if (drawerLayout.isDrawerOpen(drawer)) {
closeDrawer(drawer);
} else {
openDrawer(drawer);
}
}
void openDrawer(View toOpen) {
drawerLayout.openDrawer(toOpen);
}
void closeDrawer(View toClose) {
drawerLayout.closeDrawer(toClose);
}