wake-up-neo.com

Symbol der Navigationsleiste ändern

Ich habe Probleme, mein Navigationssymbol in ein benutzerdefiniertes zu ändern. Ich musste derzeit das Standard-Schubladensymbol implementieren, das 3 horizontale Linien oben hat, aber jetzt möchte ich dieses durch mein benutzerdefiniertes Schubladensymbol ersetzen.

So ist mein mDrawerToggle im Moment:

mDrawerToggle=new ActionBarDrawerToggle(this,
    mDrawerLayout,
    R.drawable.app_icon,
    R.string.drawer_open) {
        // My code
    };
27
Tufan

Hier ist der Beispielcode aus Erstellen eines Navigationsfachs

Activity.class

public class MainActivity extends Activity {
    private DrawerLayout mDrawerLayout;
    private ActionBarDrawerToggle mDrawerToggle;
    ...

    public void onCreate(Bundle savedInstanceState) {
        ...

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerToggle = new ActionBarDrawerToggle(
                this,                  /* Host Activity */
                mDrawerLayout,         /* DrawerLayout object */
                R.drawable.ic_drawer,  /* nav drawer icon to replace 'Up' caret */
                R.string.drawer_open,  /* "open drawer" description */
                R.string.drawer_close  /* "close drawer" description */
                ) {

            /** Called when a drawer has settled in a completely closed state. */
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                getActionBar().setTitle(mTitle);
            }

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                getActionBar().setTitle(mDrawerTitle);
            }
        };

        // Set the drawer toggle as the DrawerListener
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Pass the event to ActionBarDrawerToggle, if it returns
        // true, then it has handled the app icon touch event
        if (mDrawerToggle.onOptionsItemSelected(item)) {
          return true;
        }
        // Handle your other action bar items...

        return super.onOptionsItemSelected(item);
    }

    ...
}
8
Tarun Tak

Verwenden Sie den folgenden Code, er funktioniert für ActionBarDrawerToggle in V7

mDrawerToggle.setDrawerIndicatorEnabled(false);

mDrawerToggle.setHomeAsUpIndicator(R.drawable.your_custom_icon);
 mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
 public void onClick(View v) {
     if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) {
          mDrawerLayout.closeDrawer(GravityCompat.START);
     } else {
         mDrawerLayout.openDrawer(GravityCompat.START);
    }
}
});
39
Prashant Date

Dies ist Haupttätigkeit

final DrawerLayout drawer = (DrawerLayout) findViewById (R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle (dies, Schublade, Symbolleiste, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

    toggle.setDrawerIndicatorEnabled(false);

    toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            drawer.openDrawer(GravityCompat.START);
        }
    });

    toggle.setHomeAsUpIndicator(R.drawable.menuicon);
3
codaman

Sie können dieses Format für Ihr mDrawerToggle verwenden:

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
    R.drawable.CUSTOM_ICON, // Navigation menu toggle icon
    R.string.DRAWER_OPEN, // Navigation drawer open description
    R.string.DRAWER_CLOSE // Navigation drawer close description
    )

Ändern Sie Ihr Zeichenobjekt und stellen Sie sicher, dass es denselben Namen hat wie der im Code.

Dies ist die Hauptlayoutdatei

<Android.support.v4.widget.DrawerLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
    Android:id="@+id/drawer_layout"
    Android:layout_width="match_parent"
    Android:layout_height="match_parent" >

    <!-- Framelayout to display Fragments -->

    <FrameLayout
        Android:id="@+id/frame_container"
        Android:layout_width="match_parent"
        Android:layout_height="match_parent" />

    <!-- Listview to display slider menu -->

    <ListView
        Android:id="@+id/list_slidermenu"
        Android:layout_width="240dp"
        Android:layout_height="match_parent"
        Android:layout_gravity="start"
        Android:background="@color/white"
        Android:choiceMode="singleChoice"
        Android:divider="@color/black"
        Android:dividerHeight="1dp" />

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

Dies ist die Hauptaktivität

DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.drawable.menuicon, // nav menu toggle icon
                R.string.app_name, // nav drawer open - description for
                                    // accessibility
                R.string.app_name // nav drawer close - description for
                                    // accessibility
        ) {
            public void onDrawerClosed(View view) {
                // getActionBar().setTitle(mTitle);
                // calling onPrepareOptionsMenu() to show action bar icons
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                // getActionBar().setTitle(mDrawerTitle);
                // calling onPrepareOptionsMenu() to hide action bar icons
                invalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);

endlich bei R.drawable.menuicon (Sie können Ihre Bild-ID angeben) wird es funktionieren.

0
Hanuman