android特殊用法(转)
http://dev.10086.cn/cmdn/wiki/index.php?doc-view-2089.html
1.让一个图片透明:
- Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);buffer.eraseColor(Color.TRANSPARENT);
2. 直接发送邮件:
- Intent intent = new Intent(Intent.ACTION_SENDTO, Uri .fromParts("mailto", "test@test.com", null));
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(intent);
3. 程序控制屏幕变亮:
- WindowManager.LayoutParams lp = getWindow().getAttributes();
- lp.screenBrightness = 100 / 100.0f;
- getWindow().setAttributes(lp);
4. 过滤特定文本
- Filter filter = myAdapter.getFilter();
- filter.filter(mySearchText);
5.scrollView scroll停止事件
- setOnScrollListener(new OnScrollListener(){
- public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
- // TODO Auto-generated method stub }
- public void onScrollStateChanged(AbsListView view, int scrollState) {
- // TODO Auto-generated method stub
- if(scrollState == 0) Log.i("a", "scrolling stopped..."); } });}
6. 对于特定的程序 发起一个关联供打开
- Bitmap bmp = getImageBitmap(jpg);
- String path = getFilesDir().getAbsolutePath() + "/test.png";
- File file = new File(path);
- FileOutputStream fos = new FileOutputStream(file);
- bmp.compress( CompressFormat.PNG, 100, fos );
- fos.close();
- Intent intent = new Intent();
- intent.setAction(android .content.Intent.ACTION_VIEW);
- intent.setDataAndType(Uri .fromFile(new File(path)), "image/png");
- startActivity(intent);
- 对 于图片上边的不适用索引格式会出错。
- Intent intent = new Intent();
- intent.setAction(android .content.Intent.ACTION_VIEW);
- File file = new File("/sdcard/test.mp4");
- intent.setDataAndType(Uri .fromFile(file), "video/*");
- startActivity(intent);
- Intent intent = new Intent();
- intent.setAction(android .content.Intent.ACTION_VIEW);
- File file = new File("/sdcard/test.mp3");
- intent.setDataAndType(Uri .fromFile(file), "audio/*");
- startActivity(intent);
7. 设置文本外观
- setTextAppearance(context, android .R.style.TextAppearance_Medium);
- android :textAppearance="?android :attr/textAppearanceMedium"
8. 设置单独的发起模式:
- <activity
- android :name=".ArtistActivity"
- android :label="Artist"
- android :launchMode="singleTop">
- </activity>
- Intent i = new Intent();
- i.putExtra(EXTRA_KEY_ARTIST, id);
- i.setClass(this, ArtistActivity.class);
- i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
- startActivity(i);
9. 创建一个圆角图片
这个的主要原理其实就是利用遮罩,先创建一个圆角方框 然后将图片放在下面:
- Bitmap myCoolBitmap = ... ;
- int w = myCoolBitmap.getWidth(), h = myCoolBitmap.getHeight();
- Bitmap rounder = Bitmap.createBitmap(w,h,Bitmap.Config.ARGB_8888);
- Canvas canvas = new Canvas(rounder);
- Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
- xferPaint.setColor(Color.RED);
- canvas.drawRoundRect(new RectF(0,0,w,h), 20.0f, 20.0f, xferPaint);
- xferPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
- //然后呢实现
- canvas.drawBitmap(myCoolBitmap, 0,0, null);
- canvas.drawBitmap(rounder, 0, 0, xferPaint);
10.在notification 上的icon上加上数字 给人提示有多少个未读
- Notification notification = new Notification (icon, tickerText, when);
- notification .number = 4;
11背景渐 变:
首先建立文件drawable/shape.xml
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android ="http://schemas.android .com/apk/res/android " android :shape="rectangle">
- <gradient android :startColor="#FFFFFFFF" android :endColor="#FFFF0000"
- android :angle="270"/>
- </shape>
在该文件中设置渐变的开始颜色(startColor)、结束颜色 (endColor)和角度(angle)
接着创建一个主题values/style.xml
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <style name="NewTheme" parent="android :Theme">
- <item name="android :background">@drawable/shape</item>
- </style>
- </resources>
然 后在AndroidManifest.xml文件中的application或activity中引入该主题,如:
- <activity android :name=".ShapeDemo" android :theme="@style/NewTheme">
该 方法同样适用于控件 http://17f8.cn/trackback.php?tbID=259&extra=9d45e9
12. 储存数据 当你在一个实例中保存静态数据,此示例关闭后 下一个实例想引用 静态数据就会为null,这里呢必须重写applition
- public class MyApplication extends Application{
- private String thing = null;
- public String getThing(){
- return thing;
- }
- public void setThing( String thing ){
- this.thing = thing; }
- }
- public class MyActivity extends Activity {
- private MyApplication app;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- app = ((MyApplication)getApplication());
- String thing = app.getThing();
- }
- }
转载于:https://www.cnblogs.com/wangtianxj/archive/2010/07/26/1785073.html
android特殊用法(转)相关推荐
- 【转】 Android - LayoutInflate用法
[转自]http://blog.csdn.net/scut1135/article/details/7055461 通俗的说,inflate就相当于将一个xml中定义的布局找出来. 因为在一个Acti ...
- MTK驱动(77)---Android getevent用法
Android getevent用法 getevent命令用法如下: Usage: getevent [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-d] [ ...
- Android inflater用法
Android inflater用法 简介 具体作用 获取layoutInflater的三种方式 源码查看 返回值结果 注意 简介 在实际的开发中layoutInflater这个类的主要的主要的作用类 ...
- android plurals用法
参考 android plurals用法 对一个给定的语言和数字来说,决定使用哪一个case的规则是很复杂的,所以android提供了方法getQuantityString(),它可以用来为你选择合适 ...
- android plurals用法(单复数)
0.相关文章 android plurals用法 Android中的string资源占位符及Plurals string 1.使用 对一个给定的语言和数字来说,决定使用哪一个case的规则是很复杂的, ...
- Android.mk 用法介绍
一个Android.mk file用来向编译系统描述你的源代码.具体来说:该文件是GNU Makefile的一小部分,会被编译系统解析一次或多次.你可以在每一个Android.mk file中定义一个 ...
- android五大布局的用法,android:stretchColumns用法
TableLayout是一个使用复杂的布局,最简单的用法就仅仅是拖拉控件做出个界面,但实际上,会经常在代码里使用TableLayout,例如做出表格的效果.本文主要介绍TableLayout的基本使用 ...
- Android Scroller用法
为什么80%的码农都做不了架构师?>>> 概述 Android里Scroller类是为了实现View平滑滚动的一个Helper类.通常在自定义的View时使用,在View中定义 ...
- android queue用法,GitHub - rygz146/TQueue: Android 可以任意切换线程的任务队列, TQueue
TQueue 一个Android开发库, 可以任意切换线程的链式调用任务队列, 可添加定时, 延时任务, 统一异常处理(Ceased中断),但不影响整个任务链的运行. 具体用法如下: TQueue.q ...
- android组件用法说明,Android第三方控件PhotoView使用方法详解
Android第三方控件PhotoView使用方法详解 发布时间:2020-10-21 15:06:09 来源:脚本之家 阅读:74 作者:zhaihaohao1 PhotoView的简介: 这是一个 ...
最新文章
- Pytorch中的广播机制
- 项目代码从GitHub上克隆到本地
- MBEWH-查看历史期间的移动平均价
- 进入Google:《Google成功的七堂课》读后感
- 判别分析分为r型和q型吗_电流互感器天天见,但是你真正了解和知道它的一些注意事项吗?...
- 前端面试常考题:JS垃圾回收机制
- 远程连接linux服务器文件共享,linux mount 远程服务器共享目录
- Web Hacking 101 中文版 六、HTTP 参数污染
- SAP License:SAP传输错误所引起的系统崩溃事件反思
- Java中String的next()和nextLine()方法
- 抖音小程序达人入驻壁纸微信小程序安装教程
- 雷军在金山的奋斗历程(我的金山我的青春)
- svn报错E175002
- erpc Linux 本地环境的搭建和使用
- 迭代扩展卡尔曼滤波学习
- Linux 内核likely与unlikey
- ssm毕设项目医院预约挂号管理系统q9ig2(java+VUE+Mybatis+Maven+Mysql+sprnig)
- macOS 使用 X11 运行远端 linux 中的 x11 client 图形程序
- 推荐两个实用的PCIe工具软件
- 【自动化运维新手村】Web框架序篇
热门文章
- php 页面跳转 url地址不变,【后端开发】php跳转页面url不变
- configure: error: udev support requested but libudev header not installed
- 泰山OFFICE在LINUX上的文件图标终于全部正确
- 全网首发:FFMpeg使用NVIDIA DECODER,解码后的数据转换为YUV420P
- Dialog是逻辑字体,实际绘制时会选择不同字体
- 万恶的WIN10,已有的VirftualBox虚拟机都不能用了
- cl.exe is unable to create an executable file. C compiler test failed.
- CSDN统计出错:一天访问量竟然有48798
- 编译libpng出错:pnglibconf.c fatal error: zlib.h 没有那个文件或目录
- 晚间看图片就高亮,这体验太差