1、给文字加下划线
- <span style="font-size:18px;">email_name.setText(Html.fromHtml("<u>" + email.title + "</u>"));</span>
2、文字图片一起排,并加以间隔
- <span style="font-size:18px;"> android:drawableLeft="@drawable/user_id"
- android:drawablePadding="10dip"</span>
3、获得手机串号
- <span style="font-size:18px;">TelephonyManager telephonyManager = (TelephonyManager) MarketApplication.sContext
- .getSystemService(Context.TELEPHONY_SERVICE);
- String imei = telephonyManager.getDeviceId(); </span>
4、改变tabwidget背景色
- <span style="font-size:18px;"> tabWidget.getChildAt(i).setBackgroundResource(
- R.drawable.tab_bar_mask3);</span>
5、去掉tabhost下的白线
- <span style="font-size:18px;"> tabHost.setPadding(tabHost.getPaddingLeft(), tabHost.getPaddingTop(),
- tabHost.getPaddingRight(), tabHost.getPaddingBottom() - 10);</span>
6、获得View在控件的上下左右间距
- <span style="font-size:18px;"> 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);</span>
7、获得sd卡上的图片,并加载
- <span style="font-size:18px;">ImageView.setImageUri(Uri.fromFile(new File("/sdcard/cats.jpg"))); </span>
8、解析文字
- <span style="font-size:18px;">URLDecoder.decode(searchkeyword, "gb2312")</span>
9、Activity里嵌入Activity
- <span style="font-size:18px;"> 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());</span>
相关的变量:
- <span style="font-size:18px;"> PowerManager powerManager = null;
- WakeLock wakeLock = null;</span>
初始化:
- <span style="font-size:18px;">powerManager = (PowerManager) this
- .getSystemService(Service.POWER_SERVICE);
- wakeLock = this.powerManager.newWakeLock(
- PowerManager.SCREEN_DIM_WAKE_LOCK, "My Lock");</span>
开启屏幕常亮:
- <span style="font-size:18px;"> wakeLock.setReferenceCounted(false);
- wakeLock.acquire();</span>
关闭你的程序设置的屏幕常亮:
- <span style="font-size:18px;"> wakeLock.release();</span>
注意的地方:我在实际的调试过程中,没有设置wakeLock.setReferenceCounted(false);这个,报错为:java.lang.RuntimeException: WakeLock under-locked
阅读源码:
- <span style="font-size:18px;">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);
- }
- }
- }</span>
报错就抱在release(int flags)中,mCount为负数了,抛除了异常
我们再看下:setReferenceCounted(boolean flags);
- <span style="font-size:18px;"> public void setReferenceCounted(boolean value)
- {
- mRefCounted = value;
- }
- </span>
这个函数的作用是是不是需要计算锁的数量,设置为false时,在release()的时候,不管你acquire()了多少回,可以releaseWakeLock掉
11、不让图片变形充满整个屏幕
- <span style="font-size:18px;"> imageView.setAdjustViewBounds(true);//不让图片充满全局</span>
12、设背景色为透明
- <span style="font-size:18px;">getWindow().setBackgroundDrawable(new ColorDrawable(0));</span>
13、中文排版不整齐,一个match_parent解决问题。