navigation drawer bottom right icon android - android

I have adapted the navigation drawer with an icon in my appliccation as shown in the figure1, it seems ok.
I want to have the icon on the right bottom side of my menu as google maps did.
code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
setupSlideMenu();
}
private void setupSlideMenu() {
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout1);
addIcon();
mDrawerList = (ListView) findViewById(R.id.left_drawer1);
// Set the adapter for the list view
mDrawerList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mPlanetTitles));
// Set the list's click listener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
log("setupSlideMenu", false);
}
private void addIcon() {
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) {
getActionBar().setTitle(mTitle);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View 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);
}
Any idea?
Thanks in advance!

Use BottomDrawerToggle.
Solution was pretty simple:
Added ImageView to the android.R.id.content FrameLayout with gravity BOTTOM
Made ImageView half visible by setting right/left margin to negative value of the half of it's drawable width.
Resolved internal resource action_bar_icon_vertical_padding and used it as bottom padding of the image view
int id = Resources.getSystem().getIdentifier("action_bar_icon_vertical_padding", "dimen", "android");
float padding = mActivity.getResources().getDimension(id);
Created SlidingDrawable and calculated how to dynamically hide the the drawable as the drawer slides in/out in draw(Canvas canvas) method. Drawable is hid by clipping the Rect with drawer's amount of visible pixels.
public void draw(Canvas canvas)
{
float pixelsVisible = mOffset * mMinusShadow;
int target = (int) ((mWrapped.getIntrinsicWidth()/2)+pixelsVisible);
if(mGravity == GravityCompat.START || mGravity == Gravity.LEFT)
canvas.clipRect(target, 0, mWrapped.getIntrinsicWidth(), mWrapped.getIntrinsicHeight());
else
canvas.clipRect(0, 0, mWrapped.getIntrinsicWidth() - target,mWrapped.getIntrinsicHeight());
this.mWrapped.draw(canvas);
canvas.restore();
}

Related

How to change drawer toggle icon on Android apps?

I have created a drawer toggle on my android app. It is shown on the top-left of the screen. When I click the toggle, a list view items will be shown on the left side.
Below screen is the home screen:
when I click the toggle, it will be shown as below:
Now I want to change the icon of the toggle button by below code:
mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer);
mDrawerToggle.setDrawerIndicatorEnabled(false);
The toggle icon is changed to my drawable but the listview items will not be shown when I click the toggle. I wonder why changing the toggle icon disable the toggle click.
Below is my activity class:
public class MainActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private String[] mPlanetTitles;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
// Set the adapter for the list view
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mPlanetTitles));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout,
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer);
// mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerLayout.addDrawerListener(mDrawerToggle);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
#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 toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
/* The click listner for ListView in the navigation drawer */
private class DrawerItemClickListener implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
}
}
The v7 ActionBarDrawerToggle really only does two things: it opens/closes the drawer, and it provides the hamburger icon and its animation. Calling setDrawerIndicatorEnabled(false) will remove its icon, but it also disables the toggle. If you don't want that icon, then you're better off just not using ActionBarDrawerToggle, and handling opening/closing the drawer yourself.
First, remove all of your code for the ActionBarDrawerToggle.
Then set your desired icon with getSupportActionBar().setHomeAsUpIndicator().
In onOptionsItemSelected(), if the MenuItem's ID is android.R.id.home, open or close the drawer as appropriate.
Lastly, the DrawerLayout.DrawerListener functionality of the ActionBarDrawerToggle can be replaced with a basic SimpleDrawerListener.
public class MainActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private String[] mPlanetTitles;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
// Set the adapter for the list view
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mPlanetTitles));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// *** Set your desired icon
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer);
// *** Replace the DrawerListener functionality of the ActionBarDrawerToggle
mDrawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
#Override
public void onDrawerClosed(View view) {
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
#Override
public void onDrawerOpened(View drawerView) {
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
}
);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// *** If the home button is clicked, open/close the drawer as needed
if (item.getItemId() == android.R.id.home) {
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
}
else {
mDrawerLayout.openDrawer(GravityCompat.START);
}
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
/* The click listner for ListView in the navigation drawer */
private class DrawerItemClickListener implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
}
}
Use syncState() after changing the icon of the toggle button.
mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer);
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerToggle.syncState();

To close the Navigation Drawer on touch of screen

I am new to this Android. Here I got stuck with one problem that when I click
on Navigation Drawer item then it give other item and then on touch of screen then Navigation Drawer get closed but back button still there.
I put mDrawerLayout.ontouchlistener it does work but i want that icon back on click on screen. I does not want back button
When I click on category item inside Navigation Drawer:
Then I put another adapter with different ArrayList in ExpandableListView:
But when I touch on screen then it close Navigation Drawer but back icon is still there:
set
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);
inside your activity.
I checked in developers.android.com. They gave one small solution. Hope this works.
private ActionBarDrawerToggle mDrawerToggle;
...
private DrawerLayout mDrawerLayout;
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);
}
...
}

Android: tap on action bar doesn't open navigation drawer

Taking inspiration by the (default project inside android studio) and various sites I wanted to implement the navigation drawer as a fragment as both layout and code.But at the time the action of opening the navigation drawer when tapping the action bar does not work. Why default project works? Is it almost the same code.
code:
public class NavigationDrawerFragment extends Fragment {
/**
* Users of this fragment must call this method to set up the navigation drawer interactions.
*
* #param fragmentId The android:id of this fragment in its activity's layout.
* #param drawerLayout The DrawerLayout containing this fragment's UI.
*/
public void setUp(int fragmentId, View drawerLayout) {
Log.d(TAG,"setUp started");
if (drawerLayout instanceof DrawerLayout) {//if view smartphone
mFragmentContainerView = getActivity().findViewById(fragmentId);
mDrawerLayout = (DrawerLayout)drawerLayout;
// set a custom shadow that overlays 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
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
// ActionBarDrawerToggle ties together the the proper interactions
// between the navigation drawer and the action bar app icon.
mDrawerToggle = new ActionBarDrawerToggle(
getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
#Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
getActionBar().setTitle(getString(R.string.app_name));
}
#Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getActionBar().setTitle(getString(R.string.visualing_when_drawer_open));
if (!mUserLearnedDrawer) {
// The user manually opened the drawer; store this flag to prevent auto-showing
// the navigation drawer automatically in the future.
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
}
}
};
// If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
// per the navigation drawer design guidelines.
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
mDrawerLayout.openDrawer(mFragmentContainerView);
}
// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(new Runnable() {
#Override
public void run() {
mDrawerToggle.syncState();
}
});
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
"MainActivity":
public class MyActivity extends Activity implements NavigationDrawerFragment.NavigationDrawerCallbacks {
private final String TAG = getClass().getSimpleName();
private boolean doubleBackToExitPressedOnce;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
NavigationDrawerFragment mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
mNavigationDrawerFragment.setUp(R.id.navigation_drawer, findViewById(R.id.drawer_layout));//TODO error for tablet (not DrawerLayout but Linear)
}
If u want all the project is available at github page here (branch develop).
FIRST ATTEMPT : I tried to set this on navigationdrawerfragment class but doesn't work
#Override
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mDrawerToggle.syncState();
}
SECOND ATTEMPT : I tried to set this inside "MainActivity" but doesn't work
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
NavigationDrawerFragment.mDrawerToggle.syncState();
}
Add this to your NavigationDrawerFragment:
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// If the drawer is open, show the global app actions in the action bar. See also
// showGlobalContextActionBar, which controls the top-left area of the action bar.
if (mDrawerLayout != null && isDrawerOpen()) {
inflater.inflate(R.menu.global, menu);
showGlobalContextActionBar();
}
super.onCreateOptionsMenu(menu, inflater);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
And at this to the setup method at the end of onDrawerOpened:
getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
This is missing in your code, add this and it will probably work

Navigation drawer overlap with fragments in android

I created navigation drawer in my main activity.When i click on navigation drawer item,i am launching fragment in my main activity.if click on navigation drawer icon again,drawer is overlappng with fragment.
i want to detach fragment when i open navigation drawer second time.
Context mContext;
UIController mController;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mTitle;
private String[] mPlanetTitles = { "Photos", "Videos", "Settings" };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitle = "test";
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// 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 DrawerItemClickListener());
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) {
getActionBar().setTitle(mTitle);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mTitle);
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
#Override
protected void onDestroy() {
super.onDestroy();
}
#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);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
private class DrawerItemClickListener implements
ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView parent, View view, int position,
long id) {
selectItem(position);
mDrawerLayout.closeDrawer(mDrawerList);
}
}
public void selectItem(int position) {
switch (position) {
case 0:
getFragmentManager()
.beginTransaction()
.replace(android.R.id.content,
AlbumListFragment.newInstance()).commit();
break;
}
}
Take a look at remove(android.app.Fragment) or popBackStackImmediate()
I assume you want something like:
...
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mTitle);
//remove the fragment or pop it form the stack when you open the drawer?
getFragmentManager().popBackStackImmediate();
}
...
Hi,The below code will help you
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if (item.getItemId() == android.R.id.home) {
// If the drawer is open, close it; vice versa
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
} else {
mDrawerLayout.openDrawer(mDrawerList);
}
}
return super.onOptionsItemSelected(item);
}

Disable item in Navigation Drawer

In my Navigation Drawer I have a problem, when it loads anything in the first spot will crash the app, so my solution to this is to set it to a string that changes to say "(appname) Free" or " (appname) Premium", depending on if the premium upgrade was purchased.
I would like this unclickable as it is currently able to be clicked but nothing happens. Ideally this would be a submenu, or title, but I could not figure out how to implement that. Here is a excerpt of my code:
public class myClass extends SherlockActivity implements
OnItemSelectedListener {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private String[] mPlanetTitles;
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
mTitle = mDrawerTitle = getTitle();
if (mIsPremium == true) {
mPlanetTitles = getResources().getStringArray(
R.array.planets_array_prem);
} else {
mPlanetTitles = getResources()
.getStringArray(R.array.planets_array);
}
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// set a custom shadow that overlays 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 ActionBar app icon to behave as action to toggle nav drawer
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
supportInvalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mDrawerTitle);
supportInvalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
selectItem(0);
}
}
/* The click listener for ListView in the navigation drawer */
private class DrawerItemClickListener implements
ListView.OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
switch (position) {
case 0:
/*
* Toast.makeText( getApplicationContext(),
* "case 0 - A Activity.", Toast.LENGTH_LONG).show(); Intent
* c0 = new Intent(getBaseContext(),
* activity.class); startActivity(c0);
*/break;
case 1:
Toast.makeText(getApplicationContext(),
"case 1 - B Activity", Toast.LENGTH_LONG).show();
Intent c1 = new Intent(getBaseContext(),
ActivityB.class);
startActivity(c1);
break;
default:
}
}
}
public void selectItem(int position) {
switch (position) {
case 0:
// setContentView(R.layout.main);
break;
case 1:
setContentView(R.layout.main);
break;
default:
}
}
#Override
public void setTitle(CharSequence title) {
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
#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 toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
I do not use fragments, I was going to implement the navigation drawer by doing on click and moving to new activities. I am looking for a solution to my primary problem but would welcome any design tips.
Thank you
Edit
With CommonsWare's help I developed this: but nothing is different in my application. I want the first time (case 0 (position 0)) to be disabled.
public class MyArrayAdapter extends ArrayAdapter<String> {
public MyArrayAdapter(Context context, int position) {
super(context, 0);
}
public boolean areAllItemsEnabled() {
return false;
}
public boolean isEnabled(int position) {
if (position == 0) {
return false;
} else {
return true;
}
}
}
As you already know, since you already read the answer, you need to replace your new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles) with a custom Adapter -- perhaps one extending ArrayAdapter<String> -- where you override areAllItemsEnabled() to return false and isEnabled() to return true or false as needed.
See also:
android - disable listview item click and reenable it
Android ListView child View setEnabled() and setClickable() do nothing

Categories

Resources