写于 2016 年 03 月 03 日

  1. EditText光标颜色
    cusor.xml
    <?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <size android:width="1dp" /> <solid android:color="@android:color/white" /></shape>
    android:textCursorDrawable="@drawable/cusor"
    android:background="@null" 同时可以让底部的线消失

  2. code 21 以上,button 默认会悬浮,xml 中加入以下代码,取消悬浮
    android:stateListAnimator="@null"

  3. ContentResolver 查询图片
    Uri imageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; ContentResolver resolver = mContext.getContentResolver(); Cursor cursor = resolver.query( imageUri,//表名 null,//查询列名 MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=?",//查询条件 new String[]{"image/jpeg", "image/png"},//占位符具体值 MediaStore.Images.Media.DATE_ADDED + "DESC");//排序方式

    query()方法参数 对应SQL部分 描述
    uri from table_name 指定查询某个应用程序下的某一张表
    projection select column = value 指定查询的列名
    selection where column = value 指定where约束条件
    selectionArgs - 为where中的占位符提供具体的值
    orderBy order by column1,column2 指定查询结果的排序方式
  4. 关于 Matrix 注意
    This post might help you"http://stackoverflow.com/questions/4776570/why-does-imageview-setimagematrix-not-work" , and remember (from doc) Matrix does not have a constructor, so it must be explicitly initialized using either reset() - to construct an identity matrix, or one of the set..() functions (e.g. setTranslate, setRotate, etc.).

  5. 动态载入的 view,记得不要重复载入,会导致 oom,可以用下面代码判断

    if (inflateView == null) {
        inflateView = LayoutInflater.from(mActivity).inflate(R.layout.view, null);
    }
    
  6. Android上ListView,GridView第一行是置顶的,这样会很丑。一般为了解决这个问题都会在首行或尾行加上一个隐藏的View,或者在adapter中判断,是否是第一个设置margin。这样会很麻烦,通过设置ListView或GridView的android:clipToPadding = true,然后通过paddingTop和paddingBottom设置距离就可以搞定了。

  7. selector 在 LinearLayout之类的中没用,把 clickable = true,
    最后写normal状态,color的话需要写入drawable中

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/trans_grey"/>
    <item android:state_focused="true" android:drawable="@color/trans_grey"/>
    <item android:state_enabled="true" android:drawable="@color/white"/>
    </selector>
    
  8. 禁止EditText点击,同时不弹出键盘,设置监听事件,然后重写onTouch事件

    mEditText.setOnTouchListener(this)
    .......
    public boolean onTouch(View view, MotionEvent motionEvent) {
        if (hide){
            mEditText.setInputType(InputType.TYPE_NULL); // 关闭软键盘
        }
        switch (motionEvent.getAction()){
                case MotionEvent.ACTION_UP:
                    if (hide) {
                        //提示或者其它操作
                        return true;
                    }
                    break;
            }
        return false;
    }
    
  9. Android 定位,用第三方,自带定位没啥用,获取到经纬度以后,当心不同坐标系之间的转换,具体参考这篇文章

  10. 一个TextView里面字体不一样

    mTextView = (TextView)findViewById(R.id.test);  

         SpannableString styledText = new SpannableString("亲爱的小宝,你好");  
         styledText.setSpan(new TextAppearanceSpan(this, R.style.style0), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  
         styledText.setSpan(new TextAppearanceSpan(this, R.style.style1), 3, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  

        mTextView.setText(styledText, TextView.BufferType.SPANNABLE);