1. 颜色值计算
2. 逆向助手反编译,apktool, jd-gui,dex2jar-0.0.9.15
3. 设置图片底色: ImageView.setColorFilter()
4. 打log
StackTraceElement st[] = Thread.currentThread().getStackTrace();
for (int i = 0; i < st.length; i++) {
android.util.Log.i("silion", "trace: " + st[i].toString());
}
android.util.Log.i("silion", "--------boundary--------");
5. 卡顿时,连续onClick,同时add多个Fragment
FragmentTransaction.commitAllowingStateLoss();
FragmentManager.executePendingTransactions();
6. 文字带下划线
Strings
<resources> <string name="hello"><u>phone: 1390123456</u></string> <string name="app_name">MyLink</string> </resources>
TextView textView = (TextView)findViewById(R.id.testView); textView.setText(Html.fromHtml("<u>"+"hahaha"+"</u>"));
android:background="@null"
<string name="hello">你好,我是%1$s。</string>
String.format(context.getString(R.id.hello), "silion")
TextUtils.isEmpty(string.trim())
10. String中的部分文字设置成超链接
a. strings.xml
<string name="silion_blog">这是<a href = "http://blog.csdn.net/xilove102">silion</a>的博客</string>
TextView hyperlinkTextView = new TextView(this); hyperlinkTextView.setText(Html.fromHtml(getResources().getString(R.string.silion_blog))); hyperlinkTextView.setMovementMethod(LinkMovementMethod.getInstance());
11. 隐藏输入法
InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(hyperlinkTextView.getWindowToken(), 0); }
drawable/divider_listitem.xml
<insert xmlns:android=“http://schemas.android.com/apk/res/android" android:insert="0dp"> <shape android:shape="rectangle"> <solid android:color="@color/ca" /> </shape> </insert>
<ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="@drawable/divider_listitem" android:dividerHeight="2px" />
13. Android API Level 8及其以上Android系统提供了为应用程序数据的备份和恢复功能
android:allowBackup="true"
14. Call requires API level 18 (current min is 14):类似异常解决
15. actionLink to URI
Log.d(TAG, "performActionLink, actionLink = " + "voc://view/main"); URI uri = null; try { uri = new URI(actionLink.trim()); } catch (URISyntaxException e) { Log.e(TAG, e.getMessage(), e); } if (uri == null) { return; } String scheme = uri.getScheme() != null ? uri.getScheme() : ""; String function = uri.getHost() != null ? uri.getHost() : ""; String path = uri.getPath() != null ? uri.getPath() : ""; if (path.length() > 1) { path = path.substring(1); }
16. 字符串格式化String.format()
res\valuse\strings.xml
<string name="string_format">字符串格式化 数字:%1$d</string>MainFragment.java
titleTextView.setText(String.format(mMainActivity.getString(R.string.string_format), 0));
mViewPagerScrollTimer = new Timer(); mViewPagerScrollTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { mHandler.post(new Runnable() { @Override public void run() { int i = mHeaderViewPager.getCurrentItem() + 1; if (i >= mHeaderViewPagerAdapter.getCount()) { i = 0; } android.util.Log.v("slong.liang", "set current item = " + i); mHeaderViewPager.setCurrentItem(i); if (i == 0) { //TODO changeNormalHeaderImage(); } } }); } }, 5000, 5000);
18. 字符串编码转换
new String(str.getBytes("iso8859-1"), "utf-8")
19.URL编码
URLEncode.encode(str, "UTF-8")