2017-04-01 8 views
1

カスタムナビゲーションドロワーを作成しましたが、うまくいきましたが、このアイコンはナビゲーションドロワーの代わりにenter image description hereアイコン どのようにしてこの問題を解決できますか? 主なアクティビティナビゲーションドロワーアイコンのエラーが戻るアイコン

package abtech.waiteriano.com.dineinpos; 

import android.app.Fragment; 
import android.app.FragmentManager; 
import android.content.res.Configuration; 
import android.os.Bundle; 
import android.support.v4.app.ActionBarDrawerToggle; 
import android.support.v4.widget.DrawerLayout; 
import android.support.v7.app.AppCompatActivity; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.ListView; 

import java.util.ArrayList; 
import java.util.List; 

import abtech.waiteriano.com.dineinpos.adapters.CustomDrawerAdapter; 
import abtech.waiteriano.com.dineinpos.fragments.FragmentOne; 
import abtech.waiteriano.com.dineinpos.fragments.FragmentThree; 
import abtech.waiteriano.com.dineinpos.fragments.FragmentTwo; 
import abtech.waiteriano.com.dineinpos.gettersandsetter.DrawerItem; 

public class MainActivity extends AppCompatActivity { 

    private DrawerLayout mDrawerLayout; 
    private ListView mDrawerList; 
    private ActionBarDrawerToggle mDrawerToggle; 

    private CharSequence mDrawerTitle; 
    private CharSequence mTitle; 
    CustomDrawerAdapter adapter; 

    List<DrawerItem> dataList; 

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

     // Initializing 
     dataList = new ArrayList<DrawerItem>(); 
     mTitle = mDrawerTitle = getTitle(); 
     mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
     mDrawerList = (ListView) findViewById(R.id.left_drawer); 

//  mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, 
//    GravityCompat.START); 

     // Add Drawer Item to dataList 
     dataList.add(new DrawerItem("Order Staion", R.mipmap.ic_launcher)); 
     dataList.add(new DrawerItem("Delivery", R.mipmap.ic_launcher)); 
     dataList.add(new DrawerItem("Example 1", R.mipmap.ic_launcher)); 
     dataList.add(new DrawerItem("Example 2", R.mipmap.ic_launcher)); 

     adapter = new CustomDrawerAdapter(this, R.layout.custom_drawer_item, 
       dataList); 

     mDrawerList.setAdapter(adapter); 

     mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); 

     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

     mDrawerToggle = new ActionBarDrawerToggle(
       this, 
       mDrawerLayout, 
       R.drawable.list, /* nav drawer icon to replace 'Up' caret */ 
       R.string.drawer_open, 
       R.string.drawer_close) { 
      public void onDrawerClosed(View view) { 
       getSupportActionBar().setTitle(mTitle); 
       invalidateOptionsMenu(); 
      } 

      public void onDrawerOpened(View drawerView) { 
       getSupportActionBar().setTitle(mDrawerTitle); 
       invalidateOptionsMenu(); 
      } 
     }; 

     mDrawerLayout.setDrawerListener(mDrawerToggle); 


     if (savedInstanceState == null) { 
      SelectItem(0); 
     } 

    } 

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

    public void SelectItem(int possition) { 

     Fragment fragment = null; 
     Bundle args = new Bundle(); 
     switch (possition) { 
      case 0: 
       fragment = new FragmentOne(); 
       args.putString(FragmentOne.ITEM_NAME, dataList.get(possition) 
         .getItemName()); 
       args.putInt(FragmentOne.IMAGE_RESOURCE_ID, dataList.get(possition) 
         .getImgResID()); 
       break; 
      case 1: 
       fragment = new FragmentTwo(); 
       args.putString(FragmentTwo.ITEM_NAME, dataList.get(possition) 
         .getItemName()); 
       args.putInt(FragmentTwo.IMAGE_RESOURCE_ID, dataList.get(possition) 
         .getImgResID()); 
       break; 
      case 2: 
       fragment = new FragmentThree(); 
       args.putString(FragmentThree.ITEM_NAME, dataList.get(possition) 
         .getItemName()); 
       args.putInt(FragmentThree.IMAGE_RESOURCE_ID, dataList.get(possition) 
         .getImgResID()); 
       break; 
      case 3: 
       fragment = new FragmentOne(); 
       args.putString(FragmentOne.ITEM_NAME, dataList.get(possition) 
         .getItemName()); 
       args.putInt(FragmentOne.IMAGE_RESOURCE_ID, dataList.get(possition) 
         .getImgResID()); 
     } 

     fragment.setArguments(args); 
     FragmentManager frgManager = getFragmentManager(); 
     frgManager.beginTransaction().replace(R.id.content_frame, fragment) 
       .commit(); 

     mDrawerList.setItemChecked(possition, true); 
     setTitle(dataList.get(possition).getItemName()); 
     mDrawerLayout.closeDrawer(mDrawerList); 

    } 

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

    @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); 
     // Pass any configuration change to the drawer toggles 
     mDrawerToggle.onConfigurationChanged(newConfig); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // The action bar home/up action should open or close the drawer. 
     // ActionBarDrawerToggle will take care of this. 
     if (mDrawerToggle.onOptionsItemSelected(item)) { 
      return true; 
     } 

     return false; 
    } 

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

     } 
    } 

} 

........................................... ............................

答えて

1

コードからgetSupportActionBar().setHomeButtonEnabled(true)を削除するだけです。

FYIActionBarDrawerToggleには、引き出しアイコンの代わりにランチャーアイコンR.mipmap.ic_launcherが使用されています。

これを試してみてください:

...................... 
    ........................... 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

    mDrawerToggle = new ActionBarDrawerToggle(
         this,       
         mDrawerLayout,     
         R.drawable.YOUR_DRAWER_ICON, /* nav drawer icon to replace 'Up' caret */ 
         R.string.drawer_open,   
         R.string.drawer_close) { 
     public void onDrawerClosed(View view) { 
      getSupportActionBar().setTitle(mTitle); 
      invalidateOptionsMenu(); 
     } 

     public void onDrawerOpened(View drawerView) { 
      getSupportActionBar().setTitle(mDrawerTitle); 
      invalidateOptionsMenu(); 
     } 
    }; 

    mDrawerLayout.setDrawerListener(mDrawerToggle); 

    ............................... 
    ............................................. 

・ホープこれはあなたの助けのためにたくさん〜

+0

tahnksを助けるが、私は、私は私の編集したコードを確認してください同じ問題に直面し、これを試してみました –

関連する問題