https://m.galaxyclub.cn/?utm_source=Galaxy%20Care%20Banner&utm_medium=Galaxy%20Care%20App&utm_term=Galaxy%20Care%20Banner&utm_campaign=Galaxy%20Care%20App&utm_adgroup=Galaxy%20Care%20KV
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>
Code
TextView textView = (TextView)findViewById(R.id.testView);
textView.setText(Html.fromHtml("<u>"+"hahaha"+"</u>"));
android:background="@null"
8. String添加文字
<string name="hello">你好,我是%1$s。</string>
String.format(context.getString(R.id.hello), "silion")
9. 判断字符串是否为空(去掉首尾空格)
TextUtils.isEmpty(string.trim())
10. String中的部分文字设置成超链接
a. strings.xml
<string name="silion_blog">这是<a href = "http://blog.csdn.net/xilove102">silion</a>的博客</string>
b. java中实现
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);
}
12. 自定义ListView divider
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));
17. 定时重复执行 Timer() and TimerTask
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")
20. Cannot merge new index 65539 into a non-jumbo instruction!
:app:dexDebugUnknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
Unknown source file : com.android.dex.DexIndexOverflowException: Cannot merge new index 65539 into a non-jumbo instruction!
defaultConfig {
applicationId "com.samsung.android.voc"
minSdkVersion 19
targetSdkVersion 23
// Enabling multidex support.
multiDexEnabled true
}
</pre><pre code_snippet_id="1687924" snippet_file_name="blog_20160518_20_6479886" name="code" class="plain">
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
21. finished with non-zero exit value 3
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/openjdk-7u55/bin/java'' finished with non-zero exit value 3
dexOptions {
javaMaxHeapSize "4g"
}
22. 获取状态栏高度
/**
* 用于获取状态栏的高度。
*
* @return 返回状态栏高度的像素值。
*/
private int getStatusBarHeight() {
if (mStatusBarHeight == 0) {
try {
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
Object object = clazz.newInstance();
Field field = clazz.getField("status_bar_height");
int x = (int) field.get(object);
mStatusBarHeight = getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
}
return 0;
}
23. 设置Gradle
Use default gradle wrapper
在Android Studio系列教程一–下载与安装中新建项目成功后会下载Gradle,貌似这个过程不翻墙也是可以下载,但是访问特别慢,建议翻墙下载。那么下载的Gradle到什么地方呢?
Mac上会默认下载到 **/Users/<用户名>/.gradle/wrapper/dists** 目录
Win平台会默认下载到 C:\Documents and Settings<用户名>.gradle\wrapper\dists 目录
你会看到这个目录下有个 gradle-x.xx-all 的文件夹, 如果下载实在太慢,但是又不想翻墙的话,可以自己手动到Gradle官网下载对应的版本,然后将下载的.zip文件(也可以解压)复制到上述的gradle-x.xx-all 文件夹下,不过还是建议让它直接下载的好。
版本不对错误:
Error:Gradle version 2.2 is required. Current version is 2.10. If using the gradle wrapper, try editing the distributionUrl in D:\05_Workspace\AndroidStudio\zhbj\gradle\wrapper\gradle-wrapper.properties to gradle-2.2-all.zip.
Please fix the project's Gradle settings.
<a href="createGradleWrapper">Migrate to Gradle wrapper and sync project</a><br><a href="openGradleSettings">Gradle settings</a>
有两种方法解决:
1. 修改gradle-wrapper.properties
2.修改build.gradle -- 如果不知道版本,可以新建一个hellowrod查看
24. SDK闪退问题:
修改F:\03_AndroidDev\sdk\tools\android.bat为:
rem Check we have a valid Java.exe in the path.
set java_exe=C:\Program Files\Java\jdk1.8.0_60\bin\java.exe
rem call lib\find_java.bat
rem if not defined java_exe goto :EOF
25. 显示布局边界