下面列出了androidx.appcompat.app.ActionBar#setBackgroundDrawable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("deprecation")
public static void setColors(ActionBar actionBar, Integer value, Activity activity) {
int color = value;
SharedPreferences prefs = activity.getSharedPreferences(activity.getPackageName() + "_preferences", MODE_PRIVATE);
int drawable = iconsValues[Integer.parseInt(Objects.requireNonNull(prefs.getString("custom_icon", "0")))];
if (actionBar != null)
actionBar.setBackgroundDrawable(new ColorDrawable(color));
ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(activity.getString(R.string.app_name),
drawableToBitmap(activity.getDrawable(drawable)), color);
// ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(activity.getString(R.string.app_name),
// drawable, color);
activity.setTaskDescription(tDesc);
if (getPreferences().getBoolean("nav_bar", false)) {
activity.getWindow().setNavigationBarColor(darkenColor(color, 0.85f));
} else {
int black = activity.getResources().getColor(android.R.color.black, null);
activity.getWindow().setNavigationBarColor(black);
}
}
@SuppressLint("NewApi")
private void updateColor(float percentage)
{
if (mColorBar == null)
{
percentage = 1;
}
else
{
percentage = Math.max(0, Math.min(Float.isNaN(percentage) ? 0 : percentage, 1));
}
int alpha = (int) ((0.5 + 0.5 * percentage) * 255);
int newColor = new BlendColor(new ValueColor(mListColor), new DarkenedForStatusBar(mListColor), alpha).argb();
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(newColor));
// this is a workaround to ensure the new color is applied on all devices, some devices show a transparent ActionBar if we don't do that.
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
if (VERSION.SDK_INT >= 21)
{
Window window = getActivity().getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(new Mixed(newColor, mListColor).argb());
// window.setNavigationBarColor(mixColors(newColor, mListColor));
}
mTaskListBar.setBackgroundColor(mListColor);
if (mColorBar != null)
{
mColorBar.setBackgroundColor(mListColor);
}
}
private void setActionBarColor(MaterialColor color) {
ActionBar supportActionBar = getSupportActionBar();
if (supportActionBar == null) throw new AssertionError();
supportActionBar.setBackgroundDrawable(new ColorDrawable(color.toActionBarColor(this)));
setStatusBarColor(color.toStatusBarColor(this));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((Infinity) getApplication()).getAppComponent().inject(this);
getTheme().applyStyle(R.style.Theme_Normal, true);
getTheme().applyStyle(FontStyle.valueOf(sharedPreferences
.getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true);
getTheme().applyStyle(TitleFontStyle.valueOf(sharedPreferences
.getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true);
getTheme().applyStyle(ContentFontStyle.valueOf(sharedPreferences
.getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true);
getTheme().applyStyle(FontFamily.valueOf(sharedPreferences
.getString(SharedPreferencesUtils.FONT_FAMILY_KEY, FontFamily.Default.name())).getResId(), true);
getTheme().applyStyle(TitleFontFamily.valueOf(sharedPreferences
.getString(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY, TitleFontFamily.Default.name())).getResId(), true);
getTheme().applyStyle(ContentFontFamily.valueOf(sharedPreferences
.getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true);
setContentView(R.layout.activity_view_imgur_media);
ButterKnife.bind(this);
ActionBar actionBar = getSupportActionBar();
Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
actionBar.setHomeAsUpIndicator(upArrow);
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
setTitle(" ");
String imgurId = getIntent().getStringExtra(EXTRA_IMGUR_ID);
if (imgurId == null) {
finish();
return;
}
if (savedInstanceState != null) {
images = savedInstanceState.getParcelableArrayList(IMGUR_IMAGES_STATE);
}
haulerView.setOnDragDismissedListener(dragDirection -> {
int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down;
finish();
overridePendingTransition(0, slide);
});
if (images == null) {
fetchImgurMedia(imgurId);
} else {
progressBar.setVisibility(View.GONE);
setupViewPager();
}
errorLinearLayout.setOnClickListener(view -> fetchImgurMedia(imgurId));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((Infinity) getApplication()).getAppComponent().inject(this);
getTheme().applyStyle(R.style.Theme_Normal, true);
getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true);
getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true);
getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true);
getTheme().applyStyle(FontFamily.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.FONT_FAMILY_KEY, FontFamily.Default.name())).getResId(), true);
getTheme().applyStyle(TitleFontFamily.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY, TitleFontFamily.Default.name())).getResId(), true);
getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true);
setContentView(R.layout.activity_view_image_or_gif);
ButterKnife.bind(this);
ActionBar actionBar = getSupportActionBar();
Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
actionBar.setHomeAsUpIndicator(upArrow);
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
mHaulerView.setOnDragDismissedListener(dragDirection -> finish());
mediaDownloader = new MediaDownloaderImpl();
glide = Glide.with(this);
Intent intent = getIntent();
mImageUrl = intent.getStringExtra(GIF_URL_KEY);
if (mImageUrl == null) {
isGif = false;
mImageUrl = intent.getStringExtra(IMAGE_URL_KEY);
}
mImageFileName = intent.getStringExtra(FILE_NAME_KEY);
String postTitle = intent.getStringExtra(POST_TITLE_KEY);
if (postTitle != null) {
setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
} else {
setTitle("");
}
mHaulerView.setOnDragDismissedListener(dragDirection -> {
int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down;
finish();
overridePendingTransition(0, slide);
});
mLoadErrorLinearLayout.setOnClickListener(view -> {
mProgressBar.setVisibility(View.VISIBLE);
mLoadErrorLinearLayout.setVisibility(View.GONE);
loadImage();
});
loadImage();
gestureLayout.getController().getSettings().setMaxZoom(10f).setDoubleTapZoom(2f).setPanEnabled(true);
mImageView.setOnClickListener(view -> {
if (isActionBarHidden) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
isActionBarHidden = false;
} else {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
isActionBarHidden = true;
}
});
}
protected void configureActionBar() {
int color = ContextCompat.getColor(this, R.color.pdfViewPager_ab_color);
ActionBar ab = getSupportActionBar();
ab.setBackgroundDrawable(new ColorDrawable(color));
}