Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 多导航抽屉内容onclick操作_Java_Android_Class_Navigation Drawer_Toolbar - Fatal编程技术网

Java 多导航抽屉内容onclick操作

Java 多导航抽屉内容onclick操作,java,android,class,navigation-drawer,toolbar,Java,Android,Class,Navigation Drawer,Toolbar,具有实现自定义工具栏和导航抽屉的基本活动。在主布局上添加一些按钮之前没有问题。我在菜单文件夹下分配了多个抽屉xml文件。所以我的问题是,当我点击工具栏汉堡图标时,“R.menu.activity\u main\u drawer1”的内容正确。当我点击活动按钮时,我的其他菜单也会出现。问题就从这里开始。我的解决方案有两个问题。 工具栏汉堡图标消失或 菜单内容不正确。(当我首先单击按钮时,“R.menu.activity\u main\u drawer2”向右移动,关闭抽屉后,如果我单击工具栏菜单,

具有实现自定义工具栏和导航抽屉的基本活动。在主布局上添加一些按钮之前没有问题。我在菜单文件夹下分配了多个抽屉xml文件。所以我的问题是,当我点击工具栏汉堡图标时,“R.menu.activity\u main\u drawer1”的内容正确。当我点击活动按钮时,我的其他菜单也会出现。问题就从这里开始。我的解决方案有两个问题。 工具栏汉堡图标消失或 菜单内容不正确。(当我首先单击按钮时,“R.menu.activity\u main\u drawer2”向右移动,关闭抽屉后,如果我单击工具栏菜单,相同的“R.menu.activity\u main\u drawer2”再次出现。) 希望我能解释一下。提前谢谢

public class index extends AppCompatActivity implements View.OnClickListener{

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.index_p_activity);

    Button one = (Button) findViewById(R.id.finans);
    one.setOnClickListener(this);
    Button two = (Button) findViewById(R.id.kayit);
    two.setOnClickListener(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(index_p.this, drawer, toolbar, "open", "close");
    drawer.addDrawerListener(toggle);
    toggle.syncState();

     NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.getMenu().clear();
    navigationView.inflateMenu(R.menu.activity_main_drawer1);
}

@Override
public void onClick(View v) {

    switch (v.getId()) {
        case R.id.finans:
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(index_p.this, drawer, toolbar, "open", "close");
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.getMenu().clear();
    navigationView.inflateMenu(R.menu.activity_main_drawer2);
            break;
    }
}