下面列出了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();
}
@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);
// }
}
}
}
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;
}
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);
}
}
@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);
}
}
@Override
public void setSupportActionBar(Toolbar toolbar) {
try {
if (MizLib.hasLollipop())
toolbar.setElevation(1f);
super.setSupportActionBar(toolbar);
} catch (Throwable t) {
// Samsung pls...
}
}
public static void flattenToolbar(Toolbar toolbar) {
if (SystemUtils.runningOnLollipopOrLater() && toolbar != null) {
toolbar.setElevation(0.0f);
}
}
@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);
}
}