博客出自:http://blog.csdn.net/liuxian13183,转载注明出处! All Rights Reserved !
1、给文字加下划线
email_name.setText(Html.fromHtml("<u>" + email.title + "</u>"));
2、文字图片一起排,并加以间隔
android:drawableLeft="@drawable/user_id"
android:drawablePadding="10dip"
3、获得手机串号
TelephonyManager telephonyManager = (TelephonyManager) MarketApplication.sContext
.getSystemService(Context.TELEPHONY_SERVICE);
String imei = telephonyManager.getDeviceId();
4、改变tabwidget背景色
tabWidget.getChildAt(i).setBackgroundResource(
R.drawable.tab_bar_mask3);
tabHost.setPadding(tabHost.getPaddingLeft(), tabHost.getPaddingTop(),
tabHost.getPaddingRight(), tabHost.getPaddingBottom() - 10);
6、获得View在控件的上下左右间距
int[] loc = new int[2];
// if (fromWindowsLoc) {
// anchor.getLocationInWindow(loc);
// } else {
anchor.getLocationOnScreen(loc);
// // }
int l = loc[0];//左
int t = loc[1];//上
// 组件上下:445:474
int r = l + anchor.getWidth();// 右
int b = t + anchor.getHeight();// 下
Rect localRect = new Rect(l, t, r, b);
7、获得sd卡上的图片,并加载
ImageView.setImageUri(Uri.fromFile(new File("/sdcard/cats.jpg")));
8、解析文字
URLDecoder.decode(searchkeyword, "gb2312")
9、Activity里嵌入Activity
ll.removeAllViews();
Intent it = new Intent(new Intent(SearchActivity.this,
SearchAndroidList.class));
it.putExtra(AppData.PAPER_QUERY, query);
ll.addView(getLocalActivityManager().startActivity(
"SearchAndroidList",
it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView());
10、android 屏幕常亮保持
相关的变量:
PowerManager powerManager = null;
WakeLock wakeLock = null;
powerManager = (PowerManager) this
.getSystemService(Service.POWER_SERVICE);
wakeLock = this.powerManager.newWakeLock(
PowerManager.SCREEN_DIM_WAKE_LOCK, "My Lock");
wakeLock.setReferenceCounted(false);
wakeLock.acquire();
wakeLock.release();
acquire()函数如下:
public void acquire()
{
synchronized (mToken) {
if (!mRefCounted || mCount++ == 0) {
try {
mService.acquireWakeLock(mFlags, mToken, mTag);
} catch (RemoteException e) {
}
mHeld = true;
}
}
}
release()函数如下:
public void release()
{
release(0);
}
public void release(int flags)
{
synchronized (mToken) {
if (!mRefCounted || --mCount == 0) {
try {
mService.releaseWakeLock(mToken, flags);
} catch (RemoteException e) {
}
mHeld = false;
}
if (mCount < 0) {
throw new RuntimeException("WakeLock under-locked " + mTag);
}
}
}
public void setReferenceCounted(boolean value)
{
mRefCounted = value;
}
11、不让图片变形充满整个屏幕
imageView.setAdjustViewBounds(true);//不让图片充满全局
12、设背景色为透明
getWindow().setBackgroundDrawable(new ColorDrawable(0));