gpt4 book ai didi

android - 抽屉 View 未显示

转载 作者:行者123 更新时间:2023-11-29 19:34:47 30 4
gpt4 key购买 nike

我的抽屉 View 没有显示它在我没有对布局或 MainActivity 进行任何更改之前工作正常,现在当我检查它时什么也没显示

我的 XML

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#71b6ca"
android:id="@+id/toolbar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:title="DocVids" />

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#71b6ca"
android:id="@+id/drawerLayout"
>

<FrameLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/containerView">
</FrameLayout>



<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="-24dp"
android:id="@+id/mynav"
/>
</android.support.v4.widget.DrawerLayout>

</LinearLayout>

抽屉菜单

  <item android:title="FeedBack"
android:id="@+id/nav_item_feedback"
android:icon="@drawable/feedback_icon"/>

<item android:title="Rate Us"
android:id="@+id/nav_item_draft"
android:icon="@drawable/rateus_icon"/>



<item android:title="Others">
<menu>
<item
android:title="About"
android:icon="@drawable/about_icon"/>
<item android:title="Help"
android:icon="@drawable/help"/>
</menu>
</item>

主要 Activity

public class MainActivity extends AppCompatActivity{
DrawerLayout mDrawerLayout;
NavigationView mNavigationView;
FragmentManager mFragmentManager;
FragmentTransaction mFragmentTransaction;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


setTitle("DocVids");
/**
*Setup the DrawerLayout and NavigationView
*/

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mDrawerLayout.bringToFront();
mNavigationView = (NavigationView) findViewById(R.id.mynav) ;

/**
* Lets inflate the very first fragment
* Here , we are inflating the TabFragment as the first Fragment
*/

mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();
/**
* Setup click events on the Navigation View Items.
*/

mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
mDrawerLayout.closeDrawers();



if (menuItem.getItemId() == R.id.nav_item_feedback) {
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.containerView,new FeedBack()).commit();

}

if (menuItem.getItemId() == R.id.nav_item_fav) {
FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction();
xfragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();
}

return false;
}

});


/**
* Setup Drawer Toggle of the Toolbar
*/

android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, toolbar,R.string.app_name,
R.string.app_name);

mDrawerToggle.syncState();
//mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerLayout.addDrawerListener(mDrawerToggle);

}

最佳答案

在您的我的 xml像这样为抽屉导航制作 xml:将 DrawerLayout 作为父布局

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_home"
app:menu="@menu/activity_home_drawer" />

</android.support.v4.widget.DrawerLayout>

关于android - 抽屉 View 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39345865/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com