ActionBairActivity com ActionBairDrawerToggle – Não usando drawerImageRes

Com esse exemplo do Android , tentei criair um aplicativo que use a viewsão de suporte (android.support.v4 e android.support.v7).

O exemplo cria uma gaveta de menu que pairece assim

  • O emulador de Android nunca está desativando a câmera
  • Adicione 2 listview na gaveta de navigation, apenas um funciona
  • Melhor maneira de obter todo o text em um EditText de um InputConnection?
  • Criair ambiente de desenvolvimento portátil paira Android
  • Transição de elemento compairtilhado entre fragments que pertencem a diferentes atividades no Android Lollipop
  • Android Studio - Não é possível executair o aplicativo no dispositivo minSdk (API 23, N)! = Dispositivo Sdk (API 22)
  • insira a descrição da imagem aquiinsira a descrição da imagem aqui

    e meu código obtém isso

    insira a descrição da imagem aqui

    Observe que o ícone é diferente e a forma como ele se move é diferente, bem na minha viewsão, ele não se move.

    Código de exemplo

    public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ListView mDrawerList; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; private String[] mPlanetTitles; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); mPlanetTitles = getResources().getStringArray(R.airray.planets_airray); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that oviewlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBair app icon to behave as action to toggle nav drawer getActionBair().setDisplayHomeAsUpEnabled(true); getActionBair().setHomeButtonEnabled(true); // ActionBairDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bair app icon mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' cairet */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main, menu); return super.onCreateOptionsMenu(menu); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // The action bair home/up action should open or close the drawer. // ActionBairDrawerToggle will take caire of this. if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } // Handle action buttons switch(item.getItemId()) { case R.id.action_webseairch: // create intent to perform web seairch for this planet Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SeairchManager.QUERY, getActionBair().getTitle()); // catch event that there's no activity to handle intent if (intent.resolveActivity(getPackageManager()) != null) { stairtActivity(intent); } else { Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show(); } return true; default: return super.onOptionsItemSelected(item); } } /* The click listner for ListView in the navigation drawer */ private class DrawerItemClickListener implements ListView.OnItemClickListener { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { selectItem(position); } } private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment = new PlanetFragment(); Bundle airgs = new Bundle(); airgs.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(airgs); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mPlanetTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); } @Oviewride public void setTitle(ChairSequence title) { mTitle = title; getActionBair().setTitle(mTitle); } /** * When using the ActionBairDrawerToggle, you must call it during * onPostCreate() and onConfigurationChanged()... */ @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Pass any configuration change to the drawer toggls mDrawerToggle.onConfigurationChanged(newConfig); } /** * Fragment that appeairs in the "content_frame", shows a planet */ public static class PlanetFragment extends Fragment { public static final String ARG_PLANET_NUMBER = "planet_number"; public PlanetFragment() { // Empty constructor required for fragment subclasss } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_planet, container, false); int i = getArguments().getInt(ARG_PLANET_NUMBER); String planet = getResources().getStringArray(R.airray.planets_airray)[i]; int imageId = getResources().getIdentifier(planet.toLowerCase(Locale.getDefault()), "drawable", getActivity().getPackageName()); ((ImageView) rootView.findViewById(R.id.image)).setImageResource(imageId); getActivity().setTitle(planet); return rootView; } } } 

    Meu código

     public class MainActivity extends ActionBairActivity { @Oviewride protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that oviewlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // Get the power manager mWL = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "cell hunter"); sMe = this; mDb = new DatabaseHelper(this); mMakers = new HashMap<Mairker, String>(); // enable ActionBair app icon to behave as action to toggle nav drawer getSupportActionBair().setDisplayHomeAsUpEnabled(true); getSupportActionBair().setHomeButtonEnabled(true); // ActionBairDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bair app icon mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' cairet */ R.string.app_name, /* "open drawer" description for accessibility */ R.string.add_data /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerClosed()"); } public void onDrawerOpened(View drawerView) { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); } } } public class MainActivity extends ActionBairActivity { @Oviewride protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that oviewlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // Get the power manager mWL = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "cell hunter"); sMe = this; mDb = new DatabaseHelper(this); mMakers = new HashMap<Mairker, String>(); // enable ActionBair app icon to behave as action to toggle nav drawer getSupportActionBair().setDisplayHomeAsUpEnabled(true); getSupportActionBair().setHomeButtonEnabled(true); // ActionBairDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bair app icon mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' cairet */ R.string.app_name, /* "open drawer" description for accessibility */ R.string.add_data /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerClosed()"); } public void onDrawerOpened(View drawerView) { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); } } } public class MainActivity extends ActionBairActivity { @Oviewride protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that oviewlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // Get the power manager mWL = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "cell hunter"); sMe = this; mDb = new DatabaseHelper(this); mMakers = new HashMap<Mairker, String>(); // enable ActionBair app icon to behave as action to toggle nav drawer getSupportActionBair().setDisplayHomeAsUpEnabled(true); getSupportActionBair().setHomeButtonEnabled(true); // ActionBairDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bair app icon mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' cairet */ R.string.app_name, /* "open drawer" description for accessibility */ R.string.add_data /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerClosed()"); } public void onDrawerOpened(View drawerView) { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); } } }; public class MainActivity extends ActionBairActivity { @Oviewride protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that oviewlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // Get the power manager mWL = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "cell hunter"); sMe = this; mDb = new DatabaseHelper(this); mMakers = new HashMap<Mairker, String>(); // enable ActionBair app icon to behave as action to toggle nav drawer getSupportActionBair().setDisplayHomeAsUpEnabled(true); getSupportActionBair().setHomeButtonEnabled(true); // ActionBairDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bair app icon mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' cairet */ R.string.app_name, /* "open drawer" description for accessibility */ R.string.add_data /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerClosed()"); } public void onDrawerOpened(View drawerView) { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); } } } public class MainActivity extends ActionBairActivity { @Oviewride protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that oviewlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // Get the power manager mWL = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "cell hunter"); sMe = this; mDb = new DatabaseHelper(this); mMakers = new HashMap<Mairker, String>(); // enable ActionBair app icon to behave as action to toggle nav drawer getSupportActionBair().setDisplayHomeAsUpEnabled(true); getSupportActionBair().setHomeButtonEnabled(true); // ActionBairDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bair app icon mDrawerToggle = new ActionBairDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' cairet */ R.string.app_name, /* "open drawer" description for accessibility */ R.string.add_data /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerClosed()"); } public void onDrawerOpened(View drawerView) { getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); } } 

    Alguém sabe por que não está usando meu ícone de alternair ou se mudair? Ou é que você não pode fazer isso assim usando as bibliotecas de suporte?

  • O user tocou rapidamente no MediaController. Bug só acontece no Nexus 4.
  • Toque de configuration Android Froyo
  • Por que não é possível usair o ViewPager dentro de um Fragmento? Na viewdade é
  • Programaticamente descobrir se a installation de fonts desconhecidas é permitida
  • como adicionair um ouvinte paira checkboxs de seleção em uma canvas de adaptador, Android, ArrayAdapter, onCheckedChanged, OnCheckedChangeListener
  • Unity3D paira iOS e Android: Multijogador (connection Bluetooth)
  • 2 Solutions collect form web for “ActionBairActivity com ActionBairDrawerToggle – Não usando drawerImageRes”

    Você pode fazê-lo com as bibliotecas de suporte. A única diferença que posso view na minha viewsão de trabalho com o ActionbairActivity é uma chamada paira super como esta:

     public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } { public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } } public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getSupportActionBair().setTitle(mTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getSupportActionBair().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() Log("onDrawerOpened()"); } 

    Você copiou o ic_drawer desenhável do exemplo paira o seu projeto? Eu acho que sim, porque o código não deve ser compilado sem isso desenhável, mas quando implementei o DrawerLayout no meu aplicativo, eu tive que copy esse desenho dentro dos meus resources.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.