Java Code Examples for android.support.v7.widget.Toolbar#setElevation()

The following examples show how to use android.support.v7.widget.Toolbar#setElevation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsActivity.java    From MaterialPreferenceCompat with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_settings);

	Intent intent = getIntent();
	flag = intent.getIntExtra(EXTRA_FLAG, FLAG_HOME);

	Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		toolbar.setElevation(getResources().getDimension(R.dimen.toolbar_elevation));
	}
	setSupportActionBar(toolbar);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);

	Fragment fragment;
	switch (flag) {
		case FLAG_HOME:
		default:
			fragment = new HomeFragment();
			break;
	}
	getFragmentManager().beginTransaction()
			.replace(R.id.content, fragment)
			.commit();
}
 
Example 2
Source File: MyActionBarActivity.java    From Clip-Stack with MIT License 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        preference = PreferenceManager.getDefaultSharedPreferences(this);
        Toolbar mToolbar = (Toolbar) findViewById(R.id.my_toolbar);
        setSupportActionBar(mToolbar);

        //set toolbar shadow for phone.
        if (getString(R.string.screen_type).contains("phone")) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mToolbar.setElevation(MyUtil.dip2px(this, 4));
//            } else {
//                View mToolbarShadow = findViewById(R.id.my_toolbar_shadow);
//                if (mToolbarShadow != null) {
//                    mToolbarShadow.setVisibility(View.VISIBLE);
//                }
            }
        }
    }
 
Example 3
Source File: Phlex.java    From Phlex with Apache License 2.0 5 votes vote down vote up
public static void setToolbarElevation(Toolbar toolbar, View toolbarShadow, int elevation) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(elevation);
        toolbarShadow.setVisibility(View.GONE);
    } else {
        toolbarShadow.setVisibility(View.VISIBLE);
    }
}
 
Example 4
Source File: NestedRecyclerViewAlbumHolder.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
static Toolbar getSelectorModeToolbar(Context context,
                                      View.OnClickListener onClickListener,
                                      Toolbar.OnMenuItemClickListener onItemClickListener) {
    final Toolbar toolbar = new Toolbar(context);
    toolbar.setTag(SELECTOR_TOOLBAR_TAG);

    Theme theme = Settings.getInstance(context).getThemeInstance(context);
    int accentColor = theme.getAccentColor(context);
    int accentTextColor = theme.getAccentTextColor(context);

    toolbar.setBackgroundColor(accentColor);

    toolbar.setTitleTextColor(accentTextColor);

    toolbar.inflateMenu(R.menu.selector_mode);
    toolbar.setOnMenuItemClickListener(onItemClickListener);

    Drawable menuIcon = toolbar.getOverflowIcon();
    if (menuIcon != null) {
        DrawableCompat.wrap(menuIcon);
        DrawableCompat.setTint(menuIcon.mutate(), accentTextColor);
    }

    Drawable navIcon = ContextCompat.getDrawable(context,
            R.drawable.ic_clear_white);
    if (navIcon != null) {
        DrawableCompat.wrap(navIcon);
        DrawableCompat.setTint(navIcon.mutate(), accentTextColor);
        toolbar.setNavigationIcon(navIcon);
    }

    toolbar.setNavigationOnClickListener(onClickListener);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(context.getResources()
                .getDimension(R.dimen.toolbar_elevation));
    }
    return toolbar;
}
 
Example 5
Source File: Phlex.java    From Phlex with Apache License 2.0 5 votes vote down vote up
public static void setToolbarElevation(Toolbar toolbar, View toolbarShadow, int elevation) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(elevation);
        toolbarShadow.setVisibility(View.GONE);
    } else {
        toolbarShadow.setVisibility(View.VISIBLE);
    }
}
 
Example 6
Source File: SettingsActivity.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    int[] themes = new int[]{R.style.Theme_QuickLyric, R.style.Theme_QuickLyric_Red,
            R.style.Theme_QuickLyric_Purple, R.style.Theme_QuickLyric_Indigo,
            R.style.Theme_QuickLyric_Green, R.style.Theme_QuickLyric_Lime,
            R.style.Theme_QuickLyric_Brown, R.style.Theme_QuickLyric_Dark};
    int themeNum = Integer.valueOf(sharedPref.getString("pref_theme", "0"));
    boolean nightMode = sharedPref.getBoolean("pref_night_mode", false);
    if (nightMode && NightTimeVerifier.check(this))
        setTheme(R.style.Theme_QuickLyric_Night);
    else
        setTheme(themes[themeNum]);
    setContentView(R.layout.settings_activity);
    setStatusBarColor(null);

    Toolbar toolbar = findViewById(R.id.toolbar);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        toolbar.setElevation(8f);
    toolbar.setTitleTextColor(Color.WHITE);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_back);

    if ((getIntent().getExtras() != null && !getIntent().getExtras().getString("openedDialog", "").isEmpty()) ||
            ColorGridPreference.originalValue != null && Integer.parseInt(ColorGridPreference.originalValue) != themeNum) {
        ((ColorGridPreference) ((SettingsFragment) getFragmentManager().findFragmentByTag("SettingsFragment"))
                .findPreference("pref_theme")).showDialog(null);
        getIntent().putExtra("openedDialog", "");
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription =
                new ActivityManager.TaskDescription
                        (null, null, ((ColorDrawable) toolbar.getBackground()).getColor());
        this.setTaskDescription(taskDescription);
    }
}
 
Example 7
Source File: MizActivity.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
@Override
public void setSupportActionBar(Toolbar toolbar) {
    try {
        if (MizLib.hasLollipop())
            toolbar.setElevation(1f);

        super.setSupportActionBar(toolbar);
    } catch (Throwable t) {
        // Samsung pls...
    }
}
 
Example 8
Source File: StyleUtils.java    From IslamicLibraryAndroid with GNU General Public License v3.0 4 votes vote down vote up
public static void flattenToolbar(Toolbar toolbar) {
    if (SystemUtils.runningOnLollipopOrLater() && toolbar != null) {
        toolbar.setElevation(0.0f);
    }
}
 
Example 9
Source File: MainActivity.java    From bubble with MIT License 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportFragmentManager().addOnBackStackChangedListener(this);

    if (Utils.isLollipopOrLater()) {
        toolbar.setElevation(8);
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    mPicasso = new Picasso.Builder(this)
            .addRequestHandler(new LocalCoverHandler(this))
            .build();

    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    setupNavigationView(navigationView);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(
            this, mDrawerLayout,
            R.string.drawer_open, R.string.drawer_close);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    Scanner.getInstance().scanLibrary();

    if (savedInstanceState == null) {
        setFragment(new LibraryFragment());
        setNavBar();
        mCurrentNavItem = R.id.drawer_menu_library;
        navigationView.getMenu().findItem(mCurrentNavItem).setChecked(true);
    }
    else {
        onBackStackChanged();  // force-call method to ensure indicator is shown properly
        mCurrentNavItem = savedInstanceState.getInt(STATE_CURRENT_MENU_ITEM);
        navigationView.getMenu().findItem(mCurrentNavItem).setChecked(true);
    }
}