自学android 碰到的知识点总结

来源:互联网 发布:趣头条刷金币软件 编辑:程序博客网 时间:2024/06/02 06:25

获取当前系统版本等级

Buidl.VERSION.SDK_INT


获取当前系统内存容量

File path = Enviroment.getExternalStorageDirectory();

StatFs stat = new StatFs(path.getPath());


blockSize = stat.getBlockSizeLong();

totalBlocks = stat.getBlockCountLong();

availableBlocks = stat.getAvailablesBocksLong();


//在Manifest.xml 中配置测试框架

 <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.itheima.day03_sqlite"
        ></instrumentation>


<uses-library android:name="android.test.runner"/>


## 常用快捷键 ##

- ctrl + shift + o 导包
- ctrl + shift + t 快速查找某个类
- 先按ctrl + 2 ,再点L, 创建变量并命名
- ctrl + o , 在当前类中,快速查找某个方法
- ctrl + k, 向下查找某个字符串
- ctrl + shift + k, 向上查找某个字符串

- alt + 左方向键 跳转上一个页面

-ctrl+shift+f, 代码格式化


禁用事件三连发:

android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />


常用第三方:

xutils 来下载网络资源

TextUtils

android.text.TextUtils的类,主要的功能如下:

是否为空字符 boolean android.text.TextUtils.isEmpty(CharSequence str) 

拼接字符串 String android.text.TextUtils.join(CharSequence delimiter, Object[] tokens)

拆分字符串 String[] android.text.TextUtils.split(String text, String expression)

拆分字符串使用正则 String[] android.text.TextUtils.split(String text, Pattern pattern)

确定大小写是否有效在当前位置的文本 int android.text.TextUtils.getCapsMode(CharSequence cs, int off, int reqModes)

使用HTML编码这个字符串 String android.text.TextUtils.htmlEncode(String s)

另外,String[] android.text.TextUtils.split(String text, String expression)中的expression较特殊,如果采用

TextUtils
来分割someString的话返回的将是错误结果,正确的用法应该是
TextUtilssplit
<span style="background-color: rgb(240, 240, 240); font-family: Arial, Helvetica, sans-serif;">监听打电话使用receiver, 监听接电话使用TelephonyManager tm = getSystemService(TELEPHONY_SERVICE);</span>
adapter.notifyDataSetChanged() //刷新页面
</pre><pre class="default prettyprint prettyprinted" name="code" style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);">类似 (int flags) 对int flags 的 api描述是Additional option flags. 所有类似描述 我们都可以直接在android中传0就可以了
</pre><pre class="default prettyprint prettyprinted" name="code" style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);">子线程不能刷新UI, 如果我们只是想弹出一个toast,可以通过一下来实现
</pre>public class ToastUtils {<span style="white-space:pre"></span>public static void showToast(final Activity context, final String msg){<span style="white-space:pre"></span>if("main".equals(Thread.currentThread().getName())){<span style="white-space:pre"></span>Toast.makeText(context, msg, Toast.LENGTH_LONG).show();<span style="white-space:pre"></span>}else{<span style="white-space:pre"></span>context.runOnUiThread(new Runnable() {<span style="white-space:pre"></span><span style="white-space:pre"></span>@Override<span style="white-space:pre"></span>public void run() {<span style="white-space:pre"></span>Toast.makeText(context, msg, 1).show();<span style="white-space:pre"></span><span style="white-space:pre"></span>}<span style="white-space:pre"></span>});<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}<p>}</p><p></p><p>活动管理器 (任务管理器)  所有进程数据可以通过activitymanager 获取</p><p>AcitivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);</p><p>包管理器 :</p><p>PackageManager packageManager = getPackageManager();</p><pre class="default prettyprint prettyprinted" name="code" style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);">

0 0
原创粉丝点击