如何在我的应用上创建部分?

时间:2016-03-26 17:22:31

标签: java android

我想改进我的新应用,所以我对你有疑问。如何在导航抽屉中的应用程序中创建部分?

There's a photo if you don't understand what's in my mind. This photo is from Google Play

我的activity_main_drawer.xml

<?xml version="1.0" encoding="utf-8"?>

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_pagrindinis"
        android:icon="@drawable/ic_menu_pagrindinis"
        android:title="Pagrindinis" />
    <item
        android:id="@+id/nav_soctinklai"
        android:icon="@drawable/ic_menu_soctinklai"
        android:title="Gimnazijos socialiniai tinklai" />
    <item
        android:id="@+id/nav_dienynas"
        android:icon="@drawable/ic_menu_dienynas"
        android:title="El. dienynas" />
    <item
        android:id="@+id/nav_naudingosnuor"
        android:icon="@drawable/ic_menu_naudingosnuor"
        android:title="Naudingos nuorodos"/>
    <item
        android:id="@+id/nav_kontaktai"
        android:icon="@drawable/ic_menu_kontaktai"
        android:title="Kontaktinė informacija" />
</group>

这是MainActivity.java的摘录

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_pagrindinis) {
        //Set the fragment initially
        PagrindinisFragment fragment = new PagrindinisFragment();
        android.support.v4.app.FragmentTransaction fragmentTransaction =
                getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, fragment);
        fragmentTransaction.commit();
        // Handle the camera action
    } else if (id == R.id.nav_soctinklai) {
        //Set the fragment initially
        SocTinklaiFragment fragment = new SocTinklaiFragment();
        android.support.v4.app.FragmentTransaction fragmentTransaction =
                getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, fragment);
        fragmentTransaction.commit();

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

        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse("https://sistema.tamo.lt"));
        startActivity(i);

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

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

        KontaktaiFragment fragment = new KontaktaiFragment();
        android.support.v4.app.FragmentTransaction fragmentTransaction =
                getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, fragment);
        fragmentTransaction.commit();
    }

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

我想在这个地方制作部分。如果我按下它,它会在导航抽屉中打开更多部分。

android:id="@+id/nav_naudingosnuor"

1 个答案:

答案 0 :(得分:0)

有可用的lib尝试这样的:https://github.com/PrashamTrivedi/DrawerLayoutTest

否则您需要创建自己的可扩展列表视图。