2015年3月6日 星期五

android 9-patch image programmatically

private Drawable getThumb(int resId) {
Bitmap b = GBitmap.getResSoftBitmap(mContext, resId);
byte[] chunk = b.getNinePatchChunk();
NinePatchDrawable mapNinePatch = new NinePatchDrawable(getResources(),
b, chunk, new Rect(), null);
return mapNinePatch;
}

android EditText 光標顏色 全選字

EditText光標的顏色設定

xml
android:textCursorDrawable="@null"


程式碼
 try {
    Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
    f.setAccessible(true);
    f.set(yourEditText, R.drawable.cursor);
} catch (Exception ignored) {
}

全選EditText裡的字
editText.setSelection(0, length);
editText.setSelection(0);
editText.setSelectAllOnFocus(true);