Android 黑色样式menu
效果图:
类ImageLoader.class:
/******************************************************************************** Copyright 2011-2013 Sergey Tarasevich** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*******************************************************************************/ package com.nostra13.universalimageloader.core;import android.graphics.Bitmap; import android.text.TextUtils; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import com.nostra13.universalimageloader.cache.disc.DiscCacheAware; import com.nostra13.universalimageloader.cache.memory.MemoryCacheAware; import com.nostra13.universalimageloader.core.assist.*; import com.nostra13.universalimageloader.core.display.BitmapDisplayer; import com.nostra13.universalimageloader.core.display.FakeBitmapDisplayer; import com.nostra13.universalimageloader.utils.ImageSizeUtils; import com.nostra13.universalimageloader.utils.L;/*** Singletone for image loading and displaying at {@link ImageView ImageViews}<br />* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before any other method.** @author Sergey Tarasevich (nostra13[at]gmail[dot]com)* @since 1.0.0*/ public class ImageLoader {public static final String TAG = ImageLoader.class.getSimpleName();static final String LOG_INIT_CONFIG = "Initialize ImageLoader with configuration";static final String LOG_DESTROY = "Destroy ImageLoader";static final String LOG_LOAD_IMAGE_FROM_MEMORY_CACHE = "Load image from memory cache [%s]";private static final String WARNING_RE_INIT_CONFIG = "Try to initialize ImageLoader which had already been initialized before. "+ "To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.";private static final String ERROR_WRONG_ARGUMENTS = "Wrong arguments were passed to displayImage() method (ImageView reference must not be null)";private static final String ERROR_NOT_INIT = "ImageLoader must be init with configuration before using";private static final String ERROR_INIT_CONFIG_WITH_NULL = "ImageLoader configuration can not be initialized with null";private ImageLoaderConfiguration configuration;private ImageLoaderEngine engine;private final ImageLoadingListener emptyListener = new SimpleImageLoadingListener();private final BitmapDisplayer fakeBitmapDisplayer = new FakeBitmapDisplayer();private volatile static ImageLoader instance;/** Returns singleton class instance */public static ImageLoader getInstance() {if (instance == null) {synchronized (ImageLoader.class) {if (instance == null) {instance = new ImageLoader();}}}return instance;}protected ImageLoader() {}/*** Initializes ImageLoader instance with configuration.<br />* If configurations was set before ( {@link #isInited()} == true) then this method does nothing.<br />* To force initialization with new configuration you should {@linkplain #destroy() destroy ImageLoader} at first.** @param configuration {@linkplain ImageLoaderConfiguration ImageLoader configuration}* @throws IllegalArgumentException if <b>configuration</b> parameter is null*/public synchronized void init(ImageLoaderConfiguration configuration) {if (configuration == null) {throw new IllegalArgumentException(ERROR_INIT_CONFIG_WITH_NULL);}if (this.configuration == null) {if (configuration.writeLogs) L.d(LOG_INIT_CONFIG);engine = new ImageLoaderEngine(configuration);this.configuration = configuration;} else {L.w(WARNING_RE_INIT_CONFIG);}}/*** Returns <b>true</b> - if ImageLoader {@linkplain #init(ImageLoaderConfiguration) is initialized with* configuration}; <b>false</b> - otherwise*/public boolean isInited() {return configuration != null;}/*** Adds display image task to execution pool. Image will be set to ImageView when it's turn. <br/>* Default {@linkplain DisplayImageOptions display image options} from {@linkplain ImageLoaderConfiguration* configuration} will be used.<br />* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call** @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")* @param imageView {@link ImageView} which should display image* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before* @throws IllegalArgumentException if passed <b>imageView</b> is null*/public void displayImage(String uri, ImageView imageView) {displayImage(uri, imageView, null, null);}/*** Adds display image task to execution pool. Image will be set to ImageView when it's turn.<br />* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call** @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")* @param imageView {@link ImageView} which should display image* @param options {@linkplain DisplayImageOptions Display image options} for image displaying. If <b>null</b> -* default display image options* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from* configuration} will be used.* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before* @throws IllegalArgumentException if passed <b>imageView</b> is null*/public void displayImage(String uri, ImageView imageView, DisplayImageOptions options) {displayImage(uri, imageView, options, null);}/*** Adds display image task to execution pool. Image will be set to ImageView when it's turn.<br />* Default {@linkplain DisplayImageOptions display image options} from {@linkplain ImageLoaderConfiguration* configuration} will be used.<br />* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call** @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")* @param imageView {@link ImageView} which should display image* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI* thread.* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before* @throws IllegalArgumentException if passed <b>imageView</b> is null*/public void displayImage(String uri, ImageView imageView, ImageLoadingListener listener) {displayImage(uri, imageView, null, listener);}/*** Adds display image task to execution pool. Image will be set to ImageView when it's turn.<br />* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call** @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")* @param imageView {@link ImageView} which should display image* @param options {@linkplain DisplayImageOptions Display image options} for image displaying. If <b>null</b> -* default display image options* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from* configuration} will be used.* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI* thread.* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before* @throws IllegalArgumentException if passed <b>imageView</b> is null*/public void displayImage(String uri, ImageView imageView, DisplayImageOptions options, ImageLoadingListener listener) {checkConfiguration();if (imageView == null) {throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);}if (listener == null) {listener = emptyListener;}if (options == null) {options = configuration.defaultDisplayImageOptions;}if (TextUtils.isEmpty(uri)) {engine.cancelDisplayTaskFor(imageView);listener.onLoadingStarted(uri, imageView);if (options.shouldShowImageForEmptyUri()) {imageView.setImageResource(options.getImageForEmptyUri());} else {imageView.setImageDrawable(null);}listener.onLoadingComplete(uri, imageView, null);return;}ImageSize targetSize = ImageSizeUtils.defineTargetSizeForView(imageView, configuration.maxImageWidthForMemoryCache, configuration.maxImageHeightForMemoryCache);String memoryCacheKey = MemoryCacheUtil.generateKey(uri, targetSize);engine.prepareDisplayTaskFor(imageView, memoryCacheKey);listener.onLoadingStarted(uri, imageView);Bitmap bmp = configuration.memoryCache.get(memoryCacheKey);if (bmp != null && !bmp.isRecycled()) {if (configuration.writeLogs) L.d(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);if (options.shouldPostProcess()) {ImageLoadingInfo imageLoadingInfo = new ImageLoadingInfo(uri, imageView, targetSize, memoryCacheKey, options, listener, engine.getLockForUri(uri));ProcessAndDisplayImageTask displayTask = new ProcessAndDisplayImageTask(engine, bmp, imageLoadingInfo, options.getHandler());engine.submit(displayTask);} else {options.getDisplayer().display(bmp, imageView, LoadedFrom.MEMORY_CACHE);listener.onLoadingComplete(uri, imageView, bmp);}} else {if (options.shouldShowStubImage()) {imageView.setImageResource(options.getStubImage());} else {if (options.isResetViewBeforeLoading()) {imageView.setImageDrawable(null);}}ImageLoadingInfo imageLoadingInfo = new ImageLoadingInfo(uri, imageView, targetSize, memoryCacheKey, options, listener, engine.getLockForUri(uri));LoadAndDisplayImageTask displayTask = new LoadAndDisplayImageTask(engine, imageLoadingInfo, options.getHandler());engine.submit(displayTask);}}/*** Adds load image task to execution pool. Image will be returned with* {@link ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}.<br />* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call** @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI* thread.* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before*/public void loadImage(String uri, ImageLoadingListener listener) {loadImage(uri, null, null, listener);}/*** Adds load image task to execution pool. Image will be returned with* {@link ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}.<br />* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call** @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")* @param minImageSize Minimal size for {@link Bitmap} which will be returned in* {@linkplain ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}. Downloaded image will be decoded* and scaled to {@link Bitmap} of the size which is <b>equal or larger</b> (usually a bit larger) than* incoming minImageSize .* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI* thread.* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before*/public void loadImage(String uri, ImageSize minImageSize, ImageLoadingListener listener) {loadImage(uri, minImageSize, null, listener);}/*** Adds load image task to execution pool. Image will be returned with* {@link ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}.<br />* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call** @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")* @param options {@linkplain DisplayImageOptions Display image options} for image displaying. If <b>null</b> -* default display image options* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from* configuration} will be used.<br />* Incoming options should contain {@link FakeBitmapDisplayer} as displayer.* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI* thread.* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before*/public void loadImage(String uri, DisplayImageOptions options, ImageLoadingListener listener) {loadImage(uri, null, options, listener);}/*** Adds load image task to execution pool. Image will be returned with* {@link ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}.<br />* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call** @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")* @param targetImageSize Minimal size for {@link Bitmap} which will be returned in* {@linkplain ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}. Downloaded image will be decoded* and scaled to {@link Bitmap} of the size which is <b>equal or larger</b> (usually a bit larger) than* incoming minImageSize .* @param options {@linkplain DisplayImageOptions Display image options} for image displaying. If <b>null</b> -* default display image options* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from* configuration} will be used.<br />* Incoming options should contain {@link FakeBitmapDisplayer} as displayer.* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI* thread.* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before*/public void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options, ImageLoadingListener listener) {checkConfiguration();if (targetImageSize == null) {targetImageSize = new ImageSize(configuration.maxImageWidthForMemoryCache, configuration.maxImageHeightForMemoryCache);}if (options == null) {options = configuration.defaultDisplayImageOptions;}DisplayImageOptions optionsWithFakeDisplayer;if (options.getDisplayer() instanceof FakeBitmapDisplayer) {optionsWithFakeDisplayer = options;} else {optionsWithFakeDisplayer = new DisplayImageOptions.Builder().cloneFrom(options).displayer(fakeBitmapDisplayer).build();}ImageView fakeImage = new ImageView(configuration.context);fakeImage.setLayoutParams(new LayoutParams(targetImageSize.getWidth(), targetImageSize.getHeight()));fakeImage.setScaleType(ScaleType.CENTER_CROP);displayImage(uri, fakeImage, optionsWithFakeDisplayer, listener);}/*** Checks if ImageLoader's configuration was initialized** @throws IllegalStateException if configuration wasn't initialized*/private void checkConfiguration() {if (configuration == null) {throw new IllegalStateException(ERROR_NOT_INIT);}}/*** Returns memory cache** @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before*/public MemoryCacheAware<String, Bitmap> getMemoryCache() {checkConfiguration();return configuration.memoryCache;}/*** Clears memory cache** @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before*/public void clearMemoryCache() {checkConfiguration();configuration.memoryCache.clear();}/*** Returns disc cache** @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before*/public DiscCacheAware getDiscCache() {checkConfiguration();return configuration.discCache;}/*** Clears disc cache.** @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before*/public void clearDiscCache() {checkConfiguration();configuration.discCache.clear();}/** Returns URI of image which is loading at this moment into passed {@link ImageView} */public String getLoadingUriForView(ImageView imageView) {return engine.getLoadingUriForView(imageView);}/*** Cancel the task of loading and displaying image for passed {@link ImageView}.** @param imageView {@link ImageView} for which display task will be cancelled*/public void cancelDisplayTask(ImageView imageView) {engine.cancelDisplayTaskFor(imageView);}/*** Denies or allows ImageLoader to download images from the network.<br />* <br />* If downloads are denied and if image isn't cached then* {@link ImageLoadingListener#onLoadingFailed(String, View, FailReason)} callback will be fired with* {@link FailReason.FailType#NETWORK_DENIED}** @param denyNetworkDownloads pass <b>true</b> - to deny engine to download images from the network; <b>false</b> -* to allow engine to download images from network.*/public void denyNetworkDownloads(boolean denyNetworkDownloads) {engine.denyNetworkDownloads(denyNetworkDownloads);}/*** Sets option whether ImageLoader will use {@link FlushedInputStream} for network downloads to handle <a* href="http://code.google.com/p/android/issues/detail?id=6066">this known problem</a> or not.** @param handleSlowNetwork pass <b>true</b> - to use {@link FlushedInputStream} for network downloads; <b>false</b>* - otherwise.*/public void handleSlowNetwork(boolean handleSlowNetwork) {engine.handleSlowNetwork(handleSlowNetwork);}/*** Pause ImageLoader. All new "load&display" tasks won't be executed until ImageLoader is {@link #resume() resumed}.<br />* Already running tasks are not paused.*/public void pause() {engine.pause();}/** Resumes waiting "load&display" tasks */public void resume() {engine.resume();}/*** Cancels all running and scheduled display image tasks.<br />* ImageLoader still can be used after calling this method.*/public void stop() {engine.stop();}/*** {@linkplain #stop() Stops ImageLoader} and clears current configuration. <br />* You can {@linkplain #init(ImageLoaderConfiguration) init} ImageLoader with new configuration after calling this* method.*/public void destroy() {if (configuration != null && configuration.writeLogs) L.d(LOG_DESTROY);stop();engine = null;configuration = null;} }
调用方法:
public boolean onOptionsItemSelected(MenuItem item) {// TODO Auto-generated method stubswitch (item.getItemId()) {case R.id.menu_about:break;case R.id.menu_setting:break;case R.id.menu_history:break;case R.id.menu_feedback:break;case R.id.menu_exit:showAlertDialog("退出程序", "确定退出高仿京东商城?", "确定", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stub AppManager.getInstance().AppExit(getApplicationContext());ImageLoader.getInstance().clearMemoryCache();}}, "取消", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stub dialog.dismiss();}});break;case R.id.menu_help:break;default:break;}return true;}
出自:高仿京东商城
转载于:https://www.cnblogs.com/zhujiabin/p/4203606.html
Android 黑色样式menu相关推荐
- android 自定义menu 背景颜色,Android中设置Menu菜单的文字颜色为白色
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 开发者交流裙: 188168040 Android中设置Menu菜单的文字颜色为白色,一般情况下,Android中Menu菜单的title文字颜色为黑色, ...
- Android主题样式style背景色(图片),在刘海屏上出现黑条问题
Android主题样式style背景色(图片),在刘海屏上出现黑条问题 一般Launcher页会设置一个主题样式,配置一个背景图片来解决Activity的xml布局未显示时的一小段白屏或黑屏的时间,然 ...
- Android菜单详解——理解android中的Menu
前言 今天看了pro android 3中menu这一章,对Android的整个menu体系有了进一步的了解,故整理下笔记与大家分享. PS:强烈推荐<Pro Android 3>,是我至 ...
- Android中的Menu
文章目录 1 Menu介绍 1.1 Menu的发展 1.2 菜单的分类 2 选项菜单(OptionMenu) 2.1 选项菜单的xml文件及java文件 3 上下文菜单(ContextMenu) 3. ...
- Android 用户界面---样式和主题(Styles and Themes)(二)
样式属性 理解了样式是如何定义的之后,就需要学习<item>元素都定义了那些有效的样式属性类型.你可能已经熟悉了像layout_width和textColor属性,但是还有更多的可以使用的 ...
- android自定义样式大全:shape,selector,layer-list,style,动画全部内容
原文:http://keeganlee.me/post/android/20150830 以下摘取了部分内容: shape 一般用shape定义的xml文件存放在drawable目录下,若项目没有该目 ...
- android menu item 显示,Android 如何通过menu id来得到menu item 控件 .
Android 如何通过menu id来得到menu item 控件 . (2012-07-21 06:43:31) 标签: android 如何 杂谈 Android 如何通过menu id来得到m ...
- Android自定义样式
Android自定义样式 1.AndroidManifest.xml android:theme="@style/Theme.CustomDialog 样式要用:@style <?xm ...
- android 通知栏样式_Android通知样式
android 通知栏样式 We've discussed and implemented basic Notifications in this post. In this tutorial, we ...
- android style(样式)和theme(主题)设置
android应用程序如何设置样式,包括样式定义.单个view设置样式. 全局样式设置.样式继承关系. 1.样式定义 android的样式定义在res/values/style.xml文件中,类似we ...
最新文章
- gcc s.lds 使用方法
- AUTOML 和 NAS 的真谛
- 小时代5-perl的INC设置分析
- c++中实现delphi的按类名生成类对象
- linux物理内存虚拟内存一致,Liunx内存管理的调用和实现
- Linux 命令之 hostnamectl -- 查看/修改当前主机的信息
- linux修改grub权限,linux下肿么修改grub.cfg
- python时间格式转换time模块
- 第五周-第13章节-Python3.5-内置模块详解之Hashlib、模块
- php利用svn hooks将程序自动发布到测试环境
- java兔子问题流程图_求龟兔赛跑的流程图 高手进来瞧瞧啊
- linux内核双向链表学习
- 如何快速高效的群发Email
- 中国汉字一、二级字库的汉字与unicode编码(十六进制)对照表(收藏)
- 教学向|如何快速入门maya制作动画,萌新也能冲
- php需要session么,php – 为什么需要session_ destroy()?
- 3个超神器工具,让你的电脑比手机好玩,值得收藏
- 使用pycharm搭建数据库模型
- AFNetworking为什会请求不到数据
- Ubuntu18.04+ROS melodic 控制UR5机器人(持续更新)
热门文章
- sql server 用户'sa'登录失败(错误18456)(转载)
- Linux学习记录--命令与文件的查询
- [GDAL]3.影像金字塔构建
- html 获取mac地址,JS获取客户端IP地址与MAC地址示例
- php简单多态,PHP 对象 多态性 简单图形计算器
- python的setdefault方法
- 优雅的校验参数-javax.validation
- MYSQL当前时间与数据库里数据时间做比较
- oracle中树形数据,ORACLE树形数据解决方法
- [渝粤教育] 武汉理工大学 复变函数与积分变换 参考 资料