0

Android のナビゲーション ドロワーにハンバーガー アイコンが表示されないのはなぜですか。それがまだ表示されていないことによって行われるはずなので、私はすべてをやったのですか?

            public class Main extends ActionBarActivity {

            private String[] mPlanetTitles;
            private DrawerLayout mDrawerLayout;
            private ListView mDrawerList;
            private CharSequence mTitle;
            private ActionBarDrawerToggle mDrawerToggle;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.maina);

                mTitle = "test";

                ArrayList<Integer> draw=new ArrayList();
                draw.add(R.drawable.elec);draw.add(R.drawable.mob);draw.add(R.drawable.auto);draw.add(R.drawable.pet);draw.add(R.drawable.est);

                mPlanetTitles = new String[]{"Electronic ads", "Mobile ads", "Automobile ads","Pets ads","Real Estate ads"};
                mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
                mDrawerList = (ListView) findViewById(R.id.left_drawer);
                Adapt c=new Adapt(this,draw);
                mDrawerList.setAdapter(c);

                DisplayMetrics displayMetrics =getApplicationContext().getResources().getDisplayMetrics();
                int height=(int)((300 * displayMetrics.density) + 0.5);


                GridView g=(GridView)findViewById(R.id.gridview);


                ImageAdapter a=new ImageAdapter(this,draw);
                g.setAdapter(a);
                g.setOnItemClickListener(new AdapterView.OnItemClickListener() {


                     @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        startActivity(new Intent(Main.this, MainActivity.class));
                    }
                });


                // Set the adapter for the list view
            //    mDrawerList.setAdapter(new ArrayAdapter<String>(this,
                       // R.layout.drawer_list_item, mPlanetTitles));
                // Set the list's click listener
                mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        mDrawerList.setItemChecked(i, true);
                        //setTitle(mPlanetTitles[position]);
                        mDrawerLayout.closeDrawer(mDrawerList);
                    }
                });

                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) {
                        mDrawerToggle.syncState();
                        getSupportActionBar().setTitle(mTitle);
                        invalidateOptionsMenu();
                    }

                    /** Called when a drawer has settled in a completely open state. */
                    public void onDrawerOpened(View drawerView) {
                        mDrawerToggle.syncState();
                        getSupportActionBar().setTitle(mTitle);
                        mDrawerList.bringToFront();
                        invalidateOptionsMenu();
                    }

                };

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

                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                getSupportActionBar().setHomeButtonEnabled(true);
                getSupportActionBar().setIcon(R.drawable.ic_drawer);


            }





            @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
            protected void onPostCreate(Bundle savedInstanceState) {

                super.onPostCreate(savedInstanceState);
                mDrawerToggle.syncState();

                // Sync the toggle state after onRestoreInstanceState has occurred.

            }





            @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);
            }

            /**
             * Swaps fragments in the main content view
             */
            private void selectItem(int position) {
                Toast.makeText(this, R.string.app_name, Toast.LENGTH_SHORT).show();

                // Highlight the selected item, update the title, and close the drawer
                mDrawerList.setItemChecked(position, true);
                setTitle(mPlanetTitles[position]);
                mDrawerLayout.closeDrawer(mDrawerList);
            }




            @Override
            public void setTitle(CharSequence title) {
                mTitle = title;
                getSupportActionBar().setTitle(mTitle);
            }

            private class DrawerItemClickListener implements ListView.OnItemClickListener {
                @Override
                public void onItemClick(AdapterView parent, View view, int position, long id) {
                    selectItem(position);
                }
            }

        }

これは私のレイアウトファイルです。

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

            <!-- The main content view -->
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            <GridView
                android:id="@+id/gridview"
                android:layout_width="match_parent"
                android:numColumns="3"
                android:gravity="center"
                android:stretchMode="columnWidth"
                android:verticalSpacing="10dp"
                android:horizontalSpacing="10dp"
                android:layout_height="match_parent"/>
            </RelativeLayout>
            <!-- The navigation drawer -->
            <ListView
                android:id="@+id/left_drawer"
                android:layout_width="240dp"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:choiceMode="singleChoice"

                android:divider="@android:color/transparent"
                android:dividerHeight="0dp"
                />
        </android.support.v4.widget.DrawerLayout>

アイコンのハンバーガーが表示されないのはなぜですか?

4

2 に答える 2

1

ActionBarDrawerToggle サポート ライブラリの v4 にある非推奨バージョンを使用しているようです。IDE は、この使用法について警告する必要があります。非推奨の も使用していActionBarActivityます。

ActionBarDrawerTogglev7 サポート ライブラリにある新しいものに切り替える必要があります。

新しいものと交換するのは簡単です。インポートを変更してR.drawable.ic_drawerパラメーターを削除するだけです。新しいトグルは、ドロワー ドローアブルを提供します。

于 2015-08-07T13:49:39.357 に答える