Example usage for android.app ActionBar setHomeButtonEnabled

List of usage examples for android.app ActionBar setHomeButtonEnabled

Introduction

In this page you can find the example usage for android.app ActionBar setHomeButtonEnabled.

Prototype

public void setHomeButtonEnabled(boolean enabled) 

Source Link

Document

Enable or disable the "home" button in the corner of the action bar.

Usage

From source file:cn.jasonlv.siri.fragment.NavigationDrawerFragment.java

/**
 * 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.
 *//*from  w w  w  .j  a  v  a 2s  .  c om*/
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = 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.navigation_drawer_open, /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close /* "close drawer" description for accessibility */
    ) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }

            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }

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

            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }
    };

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

From source file:com.vmihalachi.turboeditor.activity.HomeActivity.java

/**
 * Setup the navigation drawer/*from   w  w  w.j  a va2s .c om*/
 */
private void setupNavigationDrawer() {
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    /* Action Bar */
    final ActionBar ab = getActionBar();
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setHomeButtonEnabled(true);
    /* Navigation drawer */
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer,
            R.string.nome_app_turbo_editor, R.string.nome_app_turbo_editor) {

        /**
         * {@inheritDoc}
         */
        @Override
        public void onDrawerClosed(View view) {
            invalidateOptionsMenu();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu();
        }
    };
    /* link the mDrawerToggle to the Drawer Layout */
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:com.paranoid.lukemovement.halolauncher.MainActivity.java

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

    try {/*www  . j  a  v a2 s  .co m*/
    } catch (Exception e) {
        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle("Error");
        alertDialog.setMessage(
                "This app will not work on your device because your rom does not support HALO\n\nPlease install a rom that does support this feature(e.g. 'Paranoid Android')");
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
    }

    SP = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:vn.com.vng.phim123.HomeActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_activity);

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.//from  www .  ja  v  a 2  s .  c  o m
    actionBar.setHomeButtonEnabled(true);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.manoj.macawplayer.SwipeViewActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.drawable.theme_skyblue);/*  w  w w. ja v  a2 s.c  o m*/
    requestWindowFeature(Window.FEATURE_ACTION_BAR);
    setContentView(R.layout.swipe_view);
    int actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    TextView actionBarTextView = (TextView) findViewById(actionBarTitleId);

    if (actionBarTextView != null) {
        Log.i("actionBarTextView :", "not null");
        actionBarTextView.setTextColor(Color.GREEN);
    } else
        Log.i("actionBarTextView :", "null");

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    //to remove the title and icon above the action bar
    getActionBar().setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayShowHomeEnabled(false);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    LinearLayout homeScreen = (LinearLayout) findViewById(R.id.swipeviewl);
    utilities = new Utilities();
    utilities.colorSeter(homeScreen, getApplicationContext());

    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
        /*Tab tab = actionBar.getTabAt(i);
        View v  = tab.setgetCustomView();
        v.setBackgroundResource(R.drawable.theme_skyblue);*/
    }
}

From source file:com.example.oblivion.swippedui.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btnNext = (ImageView) findViewById(R.id.a);
    btnPrev = (ImageView) findViewById(R.id.b);
    lblHeaderUserInApp = (TextView) findViewById(R.id.lblHeaderUserInApp);
    lblHeader1InApp = (TextView) findViewById(R.id.lblHeader1InApp);
    lblHeaderAgentInApp = (TextView) findViewById(R.id.lblHeaderAgentInApp);
    lblHeader2InApp = (TextView) findViewById(R.id.lblHeader2InApp);
    lblHeaderOutletInApp = (TextView) findViewById(R.id.lblHeaderOutletInApp);
    lblHeader3InApp = (TextView) findViewById(R.id.lblHeader3InApp);

    Typeface externalFont = Typeface.createFromAsset(getAssets(), "kalpurush.ttf");

    lblHeaderUserInApp.setTypeface(externalFont);
    //  lblHeader1InApp.setTypeface(externalFont);
    lblHeaderAgentInApp.setTypeface(externalFont);
    //  lblHeader2InApp.setTypeface(externalFont);
    lblHeaderOutletInApp.setTypeface(externalFont);
    //  lblHeader3InApp.setTypeface(externalFont);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent./*from  w w w. j a va 2s . c  o  m*/
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.

            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
    actionBar.hide();
    btnNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1);
        }
    });
    btnPrev.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1);
        }
    });
}

From source file:com.rastating.droidbeard.fragments.NavigationDrawerFragment.java

/**
 * 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.
 *//* www. j a v  a 2 s  . c  o  m*/
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = 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_menu_white_24dp, /* nav drawer image to replace 'Up' caret */
            R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close /* "close drawer" description for accessibility */
    ) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }

            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }

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

            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }
    };

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

From source file:com.app.blockydemo.ui.ScriptActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_script);
    ProjectManager projectManager = ProjectManager.getInstance();
    //create project
    try {//from   w  ww.j  ava 2  s. co m
        projectManager.initializeNewProject("test", this, false);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Sprite sprite = new Sprite("Back");
    projectManager.addSprite(sprite);
    projectManager.setCurrentSprite(sprite);

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    currentFragmentPosition = FRAGMENT_SCRIPTS;

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    updateCurrentFragment(currentFragmentPosition, fragmentTransaction);
    fragmentTransaction.commit();

    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);

    buttonAdd = (ImageButton) findViewById(R.id.button_add);
    updateHandleAddButtonClickListener();
}

From source file:com.appmanager.android.app.DetailActivity.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setupActionBar() {
    if (VersionUtils.isEqualOrHigherThanHoneycomb()) {
        ActionBar ab = getActionBar();
        if (ab == null) {
            return;
        }//from   www .  j a  v a2 s . co m
        if (VersionUtils.isEqualOrHigherThanIceCreamSandwich()) {
            ab.setHomeButtonEnabled(true);
        }
        ab.setDisplayHomeAsUpEnabled(true);
    }
}

From source file:com.veggies.android.todoList.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    menuTexts = new String[] { "All Lists", "Default", "Personal", "Shopping", "Wishlist", "Work",
            "Unfinished" };
    dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_list_white_24dp, menuTexts[0]));
    dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_list_white_24dp, menuTexts[1]));
    dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_person_pin_white_24dp, menuTexts[2]));
    dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_local_grocery_store_white_24dp, menuTexts[3]));
    dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_favorite_white_24dp, menuTexts[4]));
    dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_card_travel_white_24dp, menuTexts[5]));
    dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_highlight_off_white_24dp, menuTexts[6]));
    spinnerAdapter = new DropdownMenuItemAdapter(this, dropdownMenuItemList);
    //get the email passed by login UI
    Intent intent = this.getIntent();
    mEmail = intent.getStringExtra(EMAIL);
    mTitle = mDrawerTitle = getTitle();/*w  w w  .  ja  v  a 2  s  .  c  om*/
    //put the drawer items in a hash map, so we can just use it to lookup index
    mDrawerItems = new HashMap<>();
    String[] drawerArray = getResources().getStringArray(R.array.drawer_array);
    for (int i = 0; i < drawerArray.length; i++) {
        mDrawerItems.put(drawerArray[i], i);
    }
    drawerItemList.add(new DrawerItem(R.drawable.ic_list_white_24dp, "Todo List"));
    drawerItemList.add(new DrawerItem(R.drawable.ic_settings_white_24dp, "Setting"));
    BaseAdapter adapter = new DrawerItemAdapter(this, drawerItemList);
    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(adapter);
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    // enable ActionBar app icon to behave as action to toggle nav drawer
    ActionBar actionbar = getActionBar();
    actionbar.setDisplayHomeAsUpEnabled(true);
    actionbar.setHomeButtonEnabled(true);
    getActionBar().setIcon(R.drawable.logo_white);
    ColorDrawable colorDrawable = new ColorDrawable();
    colorDrawable.setColor(0xff303F9F);
    getActionBar().setBackgroundDrawable(colorDrawable);
    // 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) {
            getActionBar().setTitle(mTitle);
            if (listFragmentFlag) {
                setActionMenu();
            }
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            hideActionMenu();
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

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