2019년 11월 4일 월요일

Apply gray filter to ImageView in Android

The following code is to apply gray filter to ImageView and reset the filter.

This code requires minSdkVersion of 16.

public class ViewUtils {
    public static void applyGrayFilter(ImageView imageView) {
        ColorMatrix matrix = new ColorMatrix();
        matrix.setSaturation(0);  //0 means grayscale
        ColorMatrixColorFilter cf = new ColorMatrixColorFilter(matrix);
        imageView.setColorFilter(cf);
        imageView.setImageAlpha(128);   // 128 = 0.5
    }

    public static void resetGrayFilter(ImageView imageView) {
        imageView.setColorFilter(null);
        imageView.setImageAlpha(255);
    }
}

2019년 11월 2일 토요일

Default divider color in ListView in Android

Finding the default color of the divider color in a ListView?

The following color is the default color.

?android:attr/listDivider

2019년 10월 25일 금요일

How to hide the keypad in Android?

If you want to hide the keypad in Android, please use the following code.

private void hideKeypad() {
    // hide keypad
    final View view = getCurrentFocus();

    if (view != null) {
        final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

How to kill the current process in Android?

If you want to kill the current process in Android, please try to use the following code.

public void killProcess(Activity activity) {
    ActivityCompat.finishAffinity(activity);
    System.runFinalizersOnExit(true);
    System.exit(0);
}

FlashLite - A lite flashlight app for Android

If you find a light flashlight app, the following app is a good choice.

Please, get it on Google Play.