How to modify the Navigation Drawer to call an Activity

Asked

Viewed 398 times

2

People I created a navigation Drawer by google gallery (Navigation Drawee Activity) and would like to modify it for when I click the menu instead of calling a file extent Fragment call a normal activity, (extent Activity), I see trying the traditional way using Intent but never right, the app always closes, help me

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        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);
    }



    @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.main, 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();

        FragmentManager fragmentManager = getFragmentManager();

        //noinspection SimplifiableIfStatement
        if (id == R.id.botao_tela_status) {

            fragmentManager.beginTransaction().replace(R.id.conteudo_fragmento, new FragmentoStatusTela()).commit();

            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();
        FragmentManager fragmentManager = getFragmentManager();

        if (id == R.id.nav_quiz_tela) {

            fragmentManager.beginTransaction().replace(R.id.conteudo_fragmento, new FragmentoQuiz()).commit();

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


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

        } else if (id == R.id.desafio4) {
            Intent intent = new Intent(this, Main2Activity.class);
            startActivity(intent);
        }

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


public class Main2Activity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
    }
}

12-18 17:32:17.776 3532-3532/com.example.alexandre.nossa_historia W/PathParser: Points are too far apart 4.000000596046461
12-18 17:32:17.790 3532-3532/com.example.alexandre.nossa_historia D/AndroidRuntime: Shutting down VM
12-18 17:32:17.791 3532-3532/com.example.alexandre.nossa_historia E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.alexandre.nossa_historia, PID: 3532
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alexandre.nossa_historia/com.example.alexandre.nossa_historia.Main2Activity}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false }
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
	at android.app.ActivityThread.access$800(ActivityThread.java:151)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:135)
	at android.app.ActivityThread.main(ActivityThread.java:5254)
	at java.lang.reflect.Method.invoke(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:372)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false }
	at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:471)
	at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:325)
	at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:286)
	at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
	at com.example.alexandre.nossa_historia.Main2Activity.onCreate(Main2Activity.java:11)
	at android.app.Activity.performCreate(Activity.java:5990)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
	at android.app.ActivityThread.access$800(ActivityThread.java:151) 
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
	at android.os.Handler.dispatchMessage(Handler.java:102) 
	at android.os.Looper.loop(Looper.java:135) 
	at android.app.ActivityThread.main(ActivityThread.java:5254) 
	at java.lang.reflect.Method.invoke(Native Method) 
	at java.lang.reflect.Method.invoke(Method.java:372) 
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
12-18 17:32:20.471 3532-3532/com.example.alexandre.nossa_historia I/Process: Sending signal. PID: 3532 SIG: 9

  • Include your code in the question so people know how it is being done.

  • So helped ??

  • What Exception does when you try to open an Activity?

  • the error continues Ramaral, I can’t

  • I have edited my code please look there

  • Post the Exception together so we can help you better.

  • There is put the error that gives when clicking

  • I recommend you use this lib https://github.com/mikepenz/MaterialDrawer, always use it to create a navigation Drawer, has support for android 14 and Account header, this video explains how to use it: https://www.youtube.com/watch?v=2xpA1bY_TX4&t=14s, it saves a lot of code and time, much easier and faster than creating from scratch

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.