gpt4 book ai didi

java - 抽屉式导航栏未显示

转载 作者:太空宇宙 更新时间:2023-11-04 12:54:08 25 4
gpt4 key购买 nike

所以从字面上看,我从示例 Android 应用程序中复制了用于抽屉导航的所有内容,在示例应用程序中它显示了,在我的应用程序中则没有。

我将粘贴下面的代码,如果您需要更多文件,请告诉我!

这是代码

public class NavigacijskiIzbornik extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigacijski_izbornik);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().replace(R.id.content_frame, new NavigacijaPrviFragment()).commit();
}


@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.navigacijski_izbornik, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
FragmentManager fm = getSupportFragmentManager();
int id = item.getItemId();

if (id == R.id.nav_prviLayout) {
fm.beginTransaction().replace(R.id.content_frame, new NavigacijaDrugiFragment()).commit();

} else if (id == R.id.nav_drugiLayout) {


} else if (id == R.id.nav_treciLayout) {

} else if (id == R.id.nav_share) {

} else if (id == R.id.nav_send) {

}

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}

抽屉的 Activity

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<group android:checkableBehavior="single">
<item android:id="@+id/nav_prviLayout" android:icon="@android:drawable/ic_menu_camera"
android:title="Import" />
<item android:id="@+id/nav_drugiLayout" android:icon="@android:drawable/ic_menu_gallery"
android:title="Gallery" />
<item android:id="@+id/nav_treciLayout" android:icon="@android:drawable/ic_menu_slideshow"
android:title="Slideshow" />
<item android:id="@+id/nav_manage" android:icon="@android:drawable/ic_menu_manage"
android:title="Tools" />
</group>

<item android:title="Communicate">
<menu>
<item android:id="@+id/nav_share" android:icon="@android:drawable/ic_menu_share"
android:title="Share" />
<item android:id="@+id/nav_send" android:icon="@android:drawable/ic_menu_send"
android:title="Send" />
</menu>
</item>

</menu>

Activity 导航

<?xml version="1.0" encoding="utf-8"?>
<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">



<include
layout="@layout/app_bar_navigacijski_izbornik"
android:layout_width="match_parent"
android:layout_height="match_parent" />



<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_navigacijski_izbornik"
app:menu="@menu/activity_navigacijski_izbornik_drawer" />



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

最佳答案

像下面这样做..

  <RelativeLayout
android:id="@+id/drawer_container"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@android:color/white"
android:visibility="visible">

<include
android:id="@+id/rel_drawer_app"
layout="@layout/home_drawer" />
</RelativeLayout>

关于java - 抽屉式导航栏未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35550921/

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