android.support.v7.widget.Toolbar#setElevation ( )源码实例Demo

下面列出了android.support.v7.widget.Toolbar#setElevation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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();
}
 
源代码2 项目: Clip-Stack   文件: MyActionBarActivity.java
@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);
//                }
            }
        }
    }
 
源代码3 项目: Phlex   文件: Phlex.java
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);
    }
}
 
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;
}
 
源代码5 项目: Phlex   文件: Phlex.java
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);
    }
}
 
源代码6 项目: QuickLyric   文件: SettingsActivity.java
@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);
    }
}
 
源代码7 项目: Mizuu   文件: MizActivity.java
@Override
public void setSupportActionBar(Toolbar toolbar) {
    try {
        if (MizLib.hasLollipop())
            toolbar.setElevation(1f);

        super.setSupportActionBar(toolbar);
    } catch (Throwable t) {
        // Samsung pls...
    }
}
 
源代码8 项目: IslamicLibraryAndroid   文件: StyleUtils.java
public static void flattenToolbar(Toolbar toolbar) {
    if (SystemUtils.runningOnLollipopOrLater() && toolbar != null) {
        toolbar.setElevation(0.0f);
    }
}
 
源代码9 项目: bubble   文件: MainActivity.java
@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);
    }
}