Android 特殊用法介绍
2010-05-29 05:19:00 来源:WEB开发网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"? >
更多精彩
赞助商链接